Skip to content

Specific error codes specified with # NOQA are not detected when no colon is used #275

@asottile

Description

@asottile

In GitLab by @jeverling on Oct 26, 2018, 05:01

Omitting flake8 --bug-report and "how I installed flake8" because the bug exists in the master branch of the flake8 repo.

The regex that is used to check if there are error codes provided with a # NOQA instruction doesn't work without a colon, but it should, according to the comment in defaults.py#L33:

# We do not care about the ``: `` that follows ``noqa``

Actually the regex does not capture the error code when no colon is used, resulting in only # NOQA which suppresses all errors.

In [1]: import re

In [2]: re.compile(r"# noqa(?:: (?P<codes>([A-Z][0-9]+(?:[,\s]+)?)+))?", re.IGNORECASE).match('# NOQA: F401').groupdict()['codes'] == 'F401'
Out[2]: True

In [3]: re.compile(r"# noqa(?:: (?P<codes>([A-Z][0-9]+(?:[,\s]+)?)+))?", re.IGNORECASE).match('# NOQA F401').groupdict()['codes'] == 'F401'
Out[3]: False

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