Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set pyflake AND mypy ignore same line

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?

like image 553
senior_pimiento Avatar asked Jul 04 '18 18:07

senior_pimiento


People also ask

How do I tell MYPY to ignore a line?

You can use the form # type: ignore[<code>] to only ignore specific errors on the line.

How do I ignore a MYPY error?

You can use a special comment # type: ignore[code, ...] to only ignore errors with a specific error code (or codes) on a particular line. This can be used even if you have not configured mypy to show error codes. Currently it's only possible to disable arbitrary error codes on individual lines using this comment.


1 Answers

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.

like image 173
ethanhs Avatar answered Oct 22 '22 06:10

ethanhs