Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does pep8 fail to recognize `# noqa` in some instances?

For readability reasons, I prefer to align some types of statements, such as in the following case (this involves some PyParsing code, but that detail doesn't matter):

_otherwise_stmt = _OTHERWISE ('otherwise statement')
_else_stmt      = _ELSE      ('else statement')
_end_stmt       = _END       ('end statement')

For this, pep8 complains about E221 ("multiple spaces before operator") and E211 ("whitespace before '('"). If I put # noqa at the end of every one of the lines, pep8 still complains about these lines. However, for other constructs elsewhere in my file, the # noqa works as expected. I'm confused about why # noqa does not make pep8 work as expected for these particular constructs.

Is this a bug in the pep8 program, or am I doing something else wrong here?

like image 240
mhucka Avatar asked Feb 18 '15 21:02

mhucka


2 Answers

The pep8 script only lets you disable specific error codes with a # noqa comment.

See the Error Codes table; only error codes marked with (^) can be silenced this way. E211 and E221 are not among them (none of the E2* codes are):

(^) These checks can be disabled at the line level using the # noqa special comment. This possibility should be reserved for special cases.

Personally, I prefer using the flake8 tool, which combines pep8 with PyFlakes, and lets you use the # noqa marker far more liberally.

like image 90
Martijn Pieters Avatar answered Nov 09 '22 18:11

Martijn Pieters


This is a known issue ("# noqa not honored for most Errors"), depending on who you ask.

The tool does allow you to use # noqa for some warnings but not for E221 and E211.

like image 32
Simeon Visser Avatar answered Nov 09 '22 20:11

Simeon Visser