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
16
votes
1 answer

can flake8 *fix* my python whitespace problems?

I just learned about flake8, which calls itself "Flake8: Your Tool For Style Guide Enforcement." While flake8 will find many Python whitespace errors and enforce PEP8, it does not appear to have an option to automatically fix problematic python…
vy32
  • 28,461
  • 37
  • 122
  • 246
16
votes
3 answers

How to make pylint, flake8 or pycodestyle to automatically correct errors?

I have properly installed all of the aforementioned modules on a VM I use on Ubuntu 18.04. When running either of them on a specific script or folder, they do correctly identify style errors and output them in the console. E.g.: (venv) .../src$…
Jan
  • 264
  • 1
  • 5
  • 14
14
votes
2 answers

flake8 not honoring global configuration. elpy

I am new to emacs & trying to use it for python programming. I have installed elpy & everything is working fine except one thing - I am getting lot of warnings, errors like E401, E402, E501 etc. All are in scary red colors. After researching little…
pokiri
  • 141
  • 1
  • 4
13
votes
2 answers

running pep8 or pylint on cython code

Is there any way to use pep8 with cython files? pep8 does not work with operators for example. getline(& line) produces error: E225 missing whitespace around operator Now if i try to fix it and run this: getline( & line) produces error: E201…
Michael WS
  • 2,450
  • 4
  • 24
  • 46
13
votes
3 answers

flake8, only on diff and exclude

I'm trying to run flake8 in a pre-commit hook on only the changed files in my git diff, while also excluding files in my config file. files=$(git diff --cached --name-only --diff-filter=ACM); if flake8 --config=/path/to/config/flake8-hook.ini…
bzmw
  • 5,897
  • 3
  • 22
  • 31
12
votes
2 answers

Simplifying line length with pre-commit, flake8, black, isort, pylint, etc

When using multiple tools that either check or format python files, is there a way to set line length once for all? Currently I have: .flake8 file: max-line-length = 120 .isort.cfg file: line-length = 120 .black file: line-length = 120 .pylintrc…
Marjeta
  • 1,111
  • 10
  • 26
12
votes
1 answer

How to ignore flake8 "line too long" errors in a heredoc

Suppose I have a file with a heredoc with long lines: some_string = ''' very long lines here, 20 lines each of length 500 ''' How do I ignore all the flake8 "line too long" errors in that heredoc, without excluding the entire file from…
dfrankow
  • 20,191
  • 41
  • 152
  • 214
12
votes
1 answer

how to fix the flake 8 error "E712 comparison to False should be 'if cond is False:' or 'if not cond:'" in pandas dataframe

I am getting the flake 8 error of E712 at the line "added_parts = new_part_set[(new_part_set["duplicate"] == False) & (new_part_set["version"] == "target")]"** Following is snippet of code which we used for spreadsheet comparison source_df =…
Komera Obanna
  • 123
  • 1
  • 5
12
votes
1 answer

Flake 8: "multiple statements on one line (colon)" only for variable name starting with "if"

I'm using flake8 in Visual Studio Code, writing some code using Python 3.6 variable annotations. It worked without any problems so far, but I encountered a strange warning. This works fine: style: str = """ width: 100%; ... """ # Doing sth with…
linusg
  • 6,289
  • 4
  • 28
  • 78
12
votes
1 answer

Unintentional trailing comma that creates a tuple

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…
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
12
votes
1 answer

Flake8 Attribute Error: 'module' object has no attribute 'normalize_paths'

Here is my output of flake8 during validation: Traceback (most recent call last): File "/usr/local/bin/flake8", line 11, in sys.exit(main()) File "/usr/local/lib/python2.7/dist-packages/flake8/main.py", line 25, in main …
user6040992
11
votes
1 answer

Python black formatter conflict with rule flake8 W503 in VSCode

Anytime there is an inline assertion rule to be verified against a bool statement, using the python black formatter in VSCode will break the line causing flake8 to warn about rule W503 line break before binary operatorflake8(W503) assert ( …
Antonio Santoro
  • 827
  • 1
  • 11
  • 29
11
votes
1 answer

Pre-commit flake8 with setup.cfg in subfolder

I use flake8 with a bunch of plugins (flake8-docstrings, flake8-isort, flake8-black). I have them all pre-installed into a venv. My repo to be checked with pre-commit: Root folder has two packages Each has its own pyproject.toml (configures black…
Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119
11
votes
2 answers

How do I get Flake8 to work with F811 errors?

We're using flake8 to test our code, and we're using pytest with fixtures. The following code: from staylists.tests.fixtures import fixture1 # noqa: F401 def test_case(fixture1): # noqa: F811 # Test goes here assert 1 == 1 Generates a…
Chris B.
  • 85,731
  • 25
  • 98
  • 139
10
votes
2 answers

Change configuration of Python linter and fixer with ALE (nvim plugin)

I use ALE to manage my linting (with flake8) and code formatting (with black). One annoying incompatibility between flake8 and black is that flake8 gives an error when a line has more than 80 characters, while black only corrects lines with more…
Soap
  • 309
  • 2
  • 14
1 2
3
27 28