Description
Please describe how you installed Flake8
$ pip install flake8
Please provide the exact, unmodified output of flake8 --bug-report
{
"dependencies": [],
"platform": {
"python_implementation": "CPython",
"python_version": "3.9.5",
"system": "Linux"
},
"plugins": [
{
"is_local": false,
"plugin": "mccabe",
"version": "0.6.1"
},
{
"is_local": false,
"plugin": "pycodestyle",
"version": "2.8.0"
},
{
"is_local": false,
"plugin": "pyflakes",
"version": "2.4.0"
}
],
"version": "4.0.1"
}
Please describe the problem or feature
Hi, thank you very much for maintaining flake8!
I've updated to flake8 4.0.1 today and found that flake8
no longer emits warnings other than E999
when there is a syntax error in a file. I think this is totally OK for Python projects, but this made it impossible to apply flake8 against Cython code.
I understand maintainers here don't want to care about non-Python things, but flake8 is playing an important role for many Cython-based projects (including us) to keep the quality of code because there are no Cython linters available. Here are some examples:
- Pandas: https://github.com/pandas-dev/pandas/blob/master/flake8/cython.cfg
- CuPy: https://github.com/cupy/cupy/blob/master/.flake8.cython
- ... and many others: https://github.com/search?p=1&q=%22flake8%22+%22pyx%22&type=Code
Expected Output
% flake8 --version
3.9.2 (mccabe: 0.6.1, pycodestyle: 2.7.0, pyflakes: 2.3.1) CPython 3.9.5 on Linux
% flake8 --ignore E999 test.pyx
test.pyx:3:1: E302 expected 2 blank lines, found 1
test.pyx:6:1: E305 expected 2 blank lines after class or function definition, found 1
test.pyx:6:80: E501 line too long (84 > 79 characters)
test.pyx:6:81: E231 missing whitespace after ','
test.pyx:10:1: W391 blank line at end of file
test.pyx
:
from libc.stdint cimport intptr_t
def foo():
pass
cdef intptr_t very_very_long_function_name_that_exceepts_eighty_chars_per_line(x,y):
if x < 3:
return True
return x
Actual Output
% flake8 --version
4.0.1 (mccabe: 0.6.1, pycodestyle: 2.8.0, pyflakes: 2.4.0) CPython 3.9.5 on Linux
% flake8 --ignore E999 test.pyx
Proposal
I'm totally new to flake8 codebase, but it seems flake8 4.0 first tries to perform AST-based checks, and aborts when it fails (#1320).
- 4.0.1: https://github.com/pycqa/flake8/blob/4.0.1/src/flake8/checker.py#L596-L603
- 3.9.2: https://github.com/pycqa/flake8/blob/3.9.2/src/flake8/checker.py#L587-L596
I'd like to propose changing the logic to:
- Perform AST-based check first.
- Whether AST-based check fails or not, perform token-based check ignoring SyntaxError.
(Thanks to @toslunar who first discovered this case.)