Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A method's noqa comment is not detected correctly when using a multiline decorator #246

Closed
asottile opened this issue Apr 3, 2021 · 4 comments

Comments

@asottile
Copy link
Member

asottile commented Apr 3, 2021

In GitLab by @qxv0 on Jul 17, 2018, 07:32

Flake8 is installed using:

$ pip install flake8

flake8 --bug-report:

{
  "dependencies": [
    {
      "dependency": "setuptools",
      "version": "40.0.0"
    }
  ],
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.7.0",
    "system": "Windows"
  },
  "plugins": [
    {
      "is_local": false,
      "plugin": "ProxyChecker",
      "version": "0.0.1"
    },
    {
      "is_local": false,
      "plugin": "flake8-comprehensions",
      "version": "1.4.1"
    },
    {
      "is_local": false,
      "plugin": "flake8-docstrings",
      "version": "1.3.0, pydocstyle: 2.1.1"
    },
    {
      "is_local": false,
      "plugin": "flake8-future-import",
      "version": "0.4.5"
    },
    {
      "is_local": false,
      "plugin": "flake8-invalid-escape-sequences",
      "version": "1.3"
    },
    {
      "is_local": false,
      "plugin": "flake8-mock",
      "version": "0.3"
    },
    {
      "is_local": false,
      "plugin": "flake8-print",
      "version": "3.1.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-string-format",
      "version": "0.2.3"
    },
    {
      "is_local": false,
      "plugin": "flake8-tuple",
      "version": "0.2.13"
    },
    {
      "is_local": false,
      "plugin": "flake8_coding",
      "version": "1.3.0"
    },
    {
      "is_local": false,
      "plugin": "hacking.core",
      "version": "0.0.1"
    },
    {
      "is_local": false,
      "plugin": "mccabe",
      "version": "0.6.1"
    },
    {
      "is_local": false,
      "plugin": "naming",
      "version": "0.7.0"
    },
    {
      "is_local": false,
      "plugin": "per-file-ignores",
      "version": "0.6"
    },
    {
      "is_local": false,
      "plugin": "pycodestyle",
      "version": "2.3.1"
    },
    {
      "is_local": false,
      "plugin": "pyflakes",
      "version": "1.6.0"
    }
  ],
  "version": "3.5.0"
}

Consider the following sample code:

class C:
    @decorator(
        'a')
    def m(cls):  # noqa: N805
        pass

run flake8 on it:

mytest.py:3:9: N805 first argument of a method should be named 'self'

I expect flake8 to ignore this error per the noqa comment.

Note that the same example will work fine if the decorator is single-line:

class C:
    @decorator('a')
    def m(cls):  # noqa: N805
        pass

(no error)

I've also noticed that if the decorator is multiline one can move the noqa comment up in order for it to become effective:

class C:
    @decorator(
        'a',  # noqa: N805
        'b',
    )
    def m(cls):
        pass

(no error)

or in the case of the first sample code:

class C:
    @decorator(
        'a')  # noqa: N805
    def m(cls):
        pass

(no error)

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @qxv0 on Jul 17, 2018, 07:34

changed the description

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @qxv0 on Jul 17, 2018, 07:39

changed title from A method's noqa comment{-s-} is not detected correctly when using a multiline decorator to A method's noqa comment is not detected correctly when using a multiline decorator

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @qxv0 on Jul 17, 2018, 07:42

This is most likely a downstream issue. (The reported line number is wrong.)

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @qxv0 on Jul 17, 2018, 07:42

closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant