Set pyflake AND mypy ignore same line
Asked Answered
G

1

50

I write a module for Salt. By the documentation it adds __salt__ object into builtins. So, pyflake warn me that __salt__ is undefined when I run prospector and mypy says the same, that __salt__ is undefined! I can ignore either for pyflake with # noqa: F821 or for mypy with # type: ignore on that line.

The question is! How to ignore for both of them?

Gibbsite answered 4/7, 2018 at 18:13 Comment(3)
The code, por favor.Sling
Try # type: ignore # noqa at the end of line?Lorant
Thanks @Sling it works!Gibbsite
T
76

PEP 484 specifies towards the end of the section on type comments the following:

In some cases, linting tools or other comments may be needed on the same line as a type comment. In these cases, the type comment should be before other comments and linting markers:

# type: ignore # ~comment or other marker~

So, as Ryan Tam suggested, # type: ignore # noqa is the correct way to ignore both.

Tamah answered 5/7, 2018 at 21:21 Comment(4)
hmm... doesn't seem to work with mypy and pylint -- they both want to go firstDonnenfeld
@Donnenfeld - seems to work now for me: # type: ignore # pylint: disable=E1137Accessible
This worked for me with Pylance and flake8, # type: ignore # noqa: F821Holman
Combine mypy, flake8, and pylint (if order is correct, you need only two #): # type: ignore # noqa:F401 pylint:disable=unused-importMere

© 2022 - 2024 — McMap. All rights reserved.