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

Couldn't mute E731 errors via noqa #379

Closed
playpauseandstop opened this issue Feb 9, 2015 · 10 comments
Closed

Couldn't mute E731 errors via noqa #379

playpauseandstop opened this issue Feb 9, 2015 · 10 comments

Comments

@playpauseandstop
Copy link

I'm not sure that this is proper place, but will try.

Updating to 1.6.1 introduces new E731 errors for "do not assign a lambda expression, use a def" and results that flake8 (as well as pep8) check failed in several places.

As failed code belongs to other dev, I've tried to mute those errors by adding # noqa comments to end of failed lines, but nothing happened.

So is there any way to mute E731 errors?

@playpauseandstop
Copy link
Author

And yeah, I can exclude all E731 errors by ignoring them as command-line arg or setup.cfg directive, but I don't want to do this, I just want to mute some error lines in code

@sigmavirus24
Copy link
Member

This is one of the stronger recommendations in PEP-0008 that was only recently added to the tool. If you're going to modify those files anyway to add # noqa you may as well just fix them. Adding support for # noqa to every error code is pointless. You can also pin to an older version of pep8 or exclude those files.

@playpauseandstop
Copy link
Author

Thanks for explanation, closing this as invalid

@miki725
Copy link

miki725 commented Apr 6, 2015

what about things like:

_ = lambda x: x

which is a very common pattern in Django when translations are not ready and so using gettext is undesirable but code should be translation-ready since later on you can simply change imports to make it translatable:

from django.utils.translation import ugettext as _

in such a case I think it makes sense to enforce E731 in the rest of the file but allow to apply noqa only in specific scenarios

@sigmavirus24
Copy link
Member

So you write,

_ = lambda x: x

In every file you need it in? That seems like an anti-pattern more than a pattern. Why wouldn't you have some module where, while translations are not read, you do:

def ugettext(text):
    return text

And then do

from my_app.fake_mod import ugettext as _

Then you can very simply rewrite imports with a search for my_app.fake_mod to replace with django.utils.translation. That seems like a far more useful way of handling this.

@MrTango
Copy link

MrTango commented Jun 5, 2015

What about:
import pdb; pdb.set_trace( ) # noqa

This also not works and is a verry usefull pattern.
I know that the pdb has to be removed before commiting but for that i use pre commit hook.
And if i decide to use noqa for a statement, why should some one else decide to let this not work?

@sigmavirus24
Copy link
Member

And if i decide to use noqa for a statement, why should some one else decide to let this not work?

Because code wins. The authors of pep8 decided to only allow # noqa for controversial rules (or rules that PEP-0008 has changed over the years), not for every rule.

@amigrave
Copy link

Ok, then where can one fill the controversial form for a specific rule ? :-)

@sigmavirus24
Copy link
Member

Ok, then where can one fill the controversial form for a specific rule ? :-)

There isn't one. Flake8 3.0 is in the works and will support people using # noqa for all errors/warnings though.

@amigrave
Copy link

Excellent news! Thanks!

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

5 participants