Questions tagged [flake8]

Automatic syntax checker for Python, bundled with pycodestyle, pyflakes and mccabe.

Automatic syntax checker for Python programming language, bundled with pycodestyle, pyflakes, mccabe for easy installation and use.

410 questions
325
votes
6 answers

E731 do not assign a lambda expression, use a def

I get this pep8 warning whenever I use lambda expressions. Are lambda expressions not recommended? If not why?
Kechit Goyal
  • 3,952
  • 3
  • 20
  • 21
195
votes
3 answers

Flake8: Ignore specific warning for entire file

The Ignoring Errors docs currently list a way of ignoring a particular error for a particular line: example = lambda: 'example' # noqa: E731 ... and a way of ignoring all errors for an entire file: # flake8: noqa from foo import…
Mark Amery
  • 143,130
  • 81
  • 406
  • 459
165
votes
7 answers

How do I get flake8 to reliably ignore rules in VS Code?

Two things that annoy me. First is the warning Flake8 gives me when I type more than 80 characters on a line. Second is the warnings I get when I haven't yet used a module name that I imported. I've looked at all the documentation on using Flake8 in…
reka18
  • 7,440
  • 5
  • 16
  • 37
115
votes
6 answers

flake8 complains on boolean comparison "==" in filter clause

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…
Jruv
  • 1,438
  • 2
  • 9
  • 10
112
votes
4 answers

python pep8 class in init imported but not used

I'm doing PEP8 checks in python using the python flake8 library. I have an import statement in an __init__.py file in one of my sub-modules which looks like this: from .my_class import MyClass The reason I have this line in the init file is so that…
Salvius
  • 1,193
  • 2
  • 8
  • 8
83
votes
4 answers

what is trailing whitespace and how can I handle this?

I have some code like: if self.tagname and self.tagname2 in list1: try: question = soup.find("div", "post-text") title = soup.find("a", "question-hyperlink") …
Amy Obrian
  • 1,183
  • 2
  • 11
  • 19
57
votes
2 answers

Per-project flake8 max line length?

I'm using a Flake8 git hook in my project and I want to relax the line length limit, but only for one project. Given that it looks like there's no clear API for that, how do I modify this hook to do that? Alternatively, is there a git-config setting…
d33tah
  • 10,999
  • 13
  • 68
  • 158
55
votes
3 answers

How to tell flake8 to ignore comments

I'm using flake8 in emacs in order to clean up my python code. I find it annoying to have my comments flagged as errors (E501 line too long (x > 79 characters)). I'm wondering if anyone knows a way to kindly ask flake8 to ignore comments, both…
sacuL
  • 49,704
  • 8
  • 81
  • 106
47
votes
4 answers

flake8 - ignore warnings for a function

I'm trying to ignore warning C901 too complex for only a single function. I've tried just about ever permutation of # noqa: C901 I can see and still the error appears. I wouldq think the # noqa comment above the function (method?) be enough. I even…
notorious.no
  • 4,919
  • 3
  • 20
  • 34
45
votes
6 answers

What is the recommended way to break a long if statement? (W504 line break after binary operator)

What is currently the recommended way to break a long line of if statement with "and" and "or" operators? 1st option With the style below (which is from PEP8) with flake8, I'm getting warnings: W504 line break after binary operator: if…
ann.piv
  • 681
  • 1
  • 7
  • 17
40
votes
2 answers

flake8: Ignore only F401 rule in entire file

Is there a way to get flake8 to ignore only a specific rule for an entire file? Specifically, I'd like to ignore just F401 for an entire file. I have a file like __init__.py where I import symbols that are never used within that file. I'd rather not…
AJ Friend
  • 703
  • 1
  • 7
  • 16
38
votes
1 answer

flake8 disable linter only for a block of code

I have a file in python like: def test_constructor_for_legacy_json(): """Test if constructor works for a legacy JSON in an old database""" a = A(**{ 'field1': 'BIG TEXT WITH MORE THAN 500 CHARACTERS....(...)', 'field2': 'BIG…
Rui Martins
  • 3,337
  • 5
  • 35
  • 40
34
votes
4 answers

How to use Flake8 in VSCode?

My VSCode is using a locally installed anaconda environment, at the default directory, which places it in Program Files. Because of this I'm unable to install flake8 through VSCode, I get a permission error. If I update my conda environment at the…
Chris Macaluso
  • 1,372
  • 2
  • 14
  • 33
29
votes
5 answers

Descriptive flake8 errors in PyCharm

PyCharm does not have a built-in support for flake8 at the moment. But, flake8 can be configured to run as an external tool. Sometimes, especially for Python newcomers, not every flake8 warning is understandable and additional clarification is…
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
29
votes
6 answers

How to use flake8 for Python 3 ?

In this code snippet, def add(x:int, y:int) -> int: return x + y there are function annotations that are only supported after python 3.0 When I execute flake8 for this python code: $ flake8 7.3.py -vv checking 7.3.py def add(x: int, y: int) ->…
Cody
  • 4,353
  • 4
  • 39
  • 42
1
2 3
27 28