Skip to content

Perform token-based check even if AST build failed to allow Cython linting #1482

Closed
@kmaehashi

Description

@kmaehashi

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:

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).

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions