flake8

How to fix issues with E402?

本小妞迷上赌 提交于 2019-12-02 04:02:06
问题 We are trying to fix issues with PEP8 E402. Mostly our code is broken on: import os os.environ['LIB_CAN_THROW_ERROR_ON_IMPORT'] = 2 import lib os.environ['LIB_CAN_THROW_ERROR_ON_IMPORT'] = 0 # back - if sys.version_info[0] > 2: import python3lib else: import python2lib - try: import lib except: print('lib is required') sys.exit(1) How to solve these violations? 回答1: The guidelines specified in PEP8 are just that - guidelines. They're a set of rules to follow when they make sense. E402 refers

How to fix issues with E402?

ⅰ亾dé卋堺 提交于 2019-12-02 01:39:17
We are trying to fix issues with PEP8 E402. Mostly our code is broken on: import os os.environ['LIB_CAN_THROW_ERROR_ON_IMPORT'] = 2 import lib os.environ['LIB_CAN_THROW_ERROR_ON_IMPORT'] = 0 # back - if sys.version_info[0] > 2: import python3lib else: import python2lib - try: import lib except: print('lib is required') sys.exit(1) How to solve these violations? The guidelines specified in PEP8 are just that - guidelines. They're a set of rules to follow when they make sense. E402 refers to imports only being at the top of a file. This is to stop the following: import pygame # 800 lines of

flake8 complains on boolean comparison “==” in filter clause

回眸只為那壹抹淺笑 提交于 2019-11-30 08:53:22
问题 I have a boolean field in the mysql db table. # table model class TestCase(Base): __tablename__ = 'test_cases' ... obsoleted = Column('obsoleted', Boolean) To get the count of all the non-obsoleted test cases, that can be done simply like this: caseNum = session.query(TestCase).filter(TestCase.obsoleted == False).count() print(caseNum) That works fine, but the flake8 report the following warning: E712: Comparison to False should be "if cond is False:" or "if not cond:" Okay, I think that make

How to directly use Axes3D from matplotlib in standard plot to avoid flake8 error

只谈情不闲聊 提交于 2019-11-29 10:36:45
When using the typical 3D plot like so: from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt fig = plt.figure() ax = fig.gca(projection='3d') flake8 reports the expected error: ./tools.py:62:9: F401 'mpl_toolkits.mplot3d.Axes3D' imported but unused I know it can be avoided using the # NOQA comment. But is there a different way to formulate the projection in the figure so that the Axes3D object is used? If this is only about actually using the import at least once, you can do ax = fig.gca(projection=Axes3D.name) as "3d" is the name of the Axes3D class by which it is

Unintentional trailing comma that creates a tuple

好久不见. 提交于 2019-11-29 10:05:33
In Python, leaving a trailing comma like this is, of course, not a SyntaxError : In [1]: x = 1 , In [2]: x Out[2]: (1,) In [3]: type(x) Out[3]: tuple But, at the same time, if the trailing comma was put accidentally , it may be difficult to catch this kind of a "problem", especially for Python newcomers. I am thinking if we can catch this kind of a "problem" early , statically, with the help of PyCharm smart code quality control features; mypy , pylint or flake8 static code analysis tools. Or, another idea would be to restrict/highlight creating one item tuples implicitly without parenthesis .

flake8 complains on boolean comparison “==” in filter clause

折月煮酒 提交于 2019-11-29 09:02:31
I have a boolean field in the mysql db table. # table model class TestCase(Base): __tablename__ = 'test_cases' ... obsoleted = Column('obsoleted', Boolean) To get the count of all the non-obsoleted test cases, that can be done simply like this: caseNum = session.query(TestCase).filter(TestCase.obsoleted == False).count() print(caseNum) That works fine, but the flake8 report the following warning: E712: Comparison to False should be "if cond is False:" or "if not cond:" Okay, I think that make sense. So change my code to this: caseNum = session.query(TestCase).filter(TestCase.obsoleted is False

How to directly use Axes3D from matplotlib in standard plot to avoid flake8 error

守給你的承諾、 提交于 2019-11-28 04:12:42
问题 When using the typical 3D plot like so: from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt fig = plt.figure() ax = fig.gca(projection='3d') flake8 reports the expected error: ./tools.py:62:9: F401 'mpl_toolkits.mplot3d.Axes3D' imported but unused I know it can be avoided using the # NOQA comment. But is there a different way to formulate the projection in the figure so that the Axes3D object is used? 回答1: If this is only about actually using the import at least once, you

Unintentional trailing comma that creates a tuple

不羁岁月 提交于 2019-11-28 03:31:46
问题 In Python, leaving a trailing comma like this is, of course, not a SyntaxError : In [1]: x = 1 , In [2]: x Out[2]: (1,) In [3]: type(x) Out[3]: tuple But, at the same time, if the trailing comma was put accidentally , it may be difficult to catch this kind of a "problem", especially for Python newcomers. I am thinking if we can catch this kind of a "problem" early , statically, with the help of PyCharm smart code quality control features; mypy , pylint or flake8 static code analysis tools. Or