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

Ignore warnings on block of lines #324

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

Ignore warnings on block of lines #324

asottile opened this issue Apr 3, 2021 · 8 comments

Comments

@asottile
Copy link
Member

asottile commented Apr 3, 2021

In GitLab by @Volopas on Nov 23, 2019, 08:37

When we add special comments with noqa keyword, we can ignore either an exact line of code, or the entire file, but there is no way to ignore several lines of code without being too verbose. Nor can one ignore some but not the other warnings on the entire file.

I like how eslint tackles the whole issue. They have comments 1) able to ignore all at the same time or specific warnings; 2) the entire file, a code fragment, a current line or the one next to a current line. So their system is both flexible and complete.

The specific problem I have making me start the issue is that I have to have a bunch of lines with module-level import, not at the top of the file (E402). It looks like that:

import sys
# and other top-level imports (1)

# some configuration needed
# to import other modules (2)

# the bunch of other imports
# in the configured environment (3)

I wouldn't like disabling E402 entirely because that's just a necessary exclusion. But I can only disable E402 warning either in every single line of the block (3) or in the entire file. Both choices seem ugly or missing the point.

It would be great if flake8 would get more flexible in this way. Thank you for your efforts and for an undoubtedly useful tool.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @asottile on Nov 23, 2019, 09:59

I'd rather not if possible

Have you tried extend-ignore / per-file-ignores? It sounds like those would solve your problem just as well

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @Volopas on Nov 23, 2019, 12:36

Thanks, so we can ignore some particular warnings on a per-file basis and use inheritance to extend the list down the hierarchy. That'll be definitely helpful for me in the future. It's a pity though we cannot mark a code fragment larger than a couple of lines and smaller than a file in a concise manner. I wouldn't like to ignore E402 entirely for the file, I'd rather follow it with this particular case excluded.

It seems you see some flaws in inline ignores that make them somewhat unwanted. What's your opinion on the matter?

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @asottile on Nov 25, 2019, 08:13

I'm mostly hesitant because there's already working solutions to this problem and implementing the suggested feature would be potentially complicated (and something we'd have to support for forever). The inclusion/exclusion/ignore functionality is already some of the most complicated parts of flake8.

I think inline ignores are fine as is for 99.9% of cases -- the case you're suggesting is particularly exceptional in my opinion (and as such I'm hesitant to implement a big complex feature for it)

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @Volopas on Nov 25, 2019, 17:20

I agree the feature is not very crucial and more of refinement than of real necessity. I don't think the case is extremely rare, but neither the feature is worth a lot of effort. Thank you.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @Volopas on Nov 25, 2019, 17:20

closed

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @asottile on Nov 25, 2019, 20:14

thanks for the issue though -- if it becomes easier to implement in the future (I hope it will!) we'll consider this :)

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Nov 26, 2019, 05:04

Also worth noting that the way that Flake8 works today it might not be awful to implement. We have the ability to have a StyleGuide per file. I suspect we could do something hacky on the fly and copy that with the block settings but that requires far more awareness and would require a fundamental change of where we decide whether to report an error or not (based on config)

@bva99
Copy link

bva99 commented May 5, 2022

In GitLab by @asottile on Nov 25, 2019, 20:14

thanks for the issue though -- if it becomes easier to implement in the future (I hope it will!) we'll consider this :)

Please reconsider this 🙏

@PyCQA PyCQA locked as spam and limited conversation to collaborators Feb 7, 2023
@PyCQA PyCQA deleted a comment from gavincyi Feb 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants