-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add an option to flag forbidden imports on the line at which they occur #411
Conversation
This comment has been minimized.
This comment has been minimized.
We can probably avoid having to add a thousand million |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The isort thing is fixed now by using |
Seems like there's a bigger problem: on 3.8 and 3.9 aliases don't have a lineno, so we can only do this on 3.10+ :( That creates the problem that the location of |
Co-authored-by: Jelle Zijlstra <[email protected]>
This comment has been minimized.
This comment has been minimized.
I'm not too worried about errors being reported on different lines for different versions. I feel like if we can give a more specific lineno for an error, we should, and I'm guessing most projects only run flake8 with a fairly recent Python version in CI -- so hopefully they won't be too annoyed with having errors reported on different linenos on different Python versions. |
I am however not sure what a clean way to test this behaviour would be. Our test suite can't currently handle errors being reported on different lines, depending on which Python version you're using. I can think of various workarounds, but none that I like. |
This comment has been minimized.
This comment has been minimized.
Following 17698fa, this PR no longer makes the plugin crash on py39, but the tests still fail due to the incorrect line numbers on py39. |
@JelleZijlstra, thoughts on maybe gating this behaviour behind a flag? |
I'm not too fond of adding flags, it's generally better to have consistent behavior. It's definitely an option though. We could probably handle this in the test suite by having separate test files per Python version. |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This change has no effect on typeshed. 🤖🎉 |
In general I definitely agree. However, I think a flag is a good option here for two reasons:
|
I think we should prefer consistent behavior, and it is less important what line number the error points at. If we want to proceed with this PR, I'd suggest we make something hacky that gets the new behavior on Python 3.8 and 3.9, and we put it inside a |
I don't think it would be possible to do that on Python 3.9 in a reliable way without using the tokenizer, which I'm sorta reluctant to do since we currently only use the AST in flake8-pyi. So maybe we should just drop this PR for now, until we drop support for Python 3.9 (which will be a while off)? It's not really crucial to flag the bad import on the exact line it occurs on; just a nice-to-have, really. |
Agreed, maybe we should just do this later :) |
I'll wait to see if Jelle has any ideas that I'm missing; if not, I'll just close this :) |
I don't have any better ideas than dropping support for 3.8 and 3.9, and it's a bit early for that. |
I opened #413 so we remember to do this when we drop support for Python 3.9 :) |
No description provided.