Move import to module scope #5789
dmartin
started this conversation in
Enhancement
Replies: 1 comment
-
Thanks for the suggestion. Moving to discussions for up votes. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Sometimes, in the middle of writing a method or function, it turns out that you need to reference an item which has not been imported yet. When auto-import or "add import" code actions work, it's no problem. But those systems don't work in all cases, and when do you need to manually add a top-level import, it requires a bit of a mental context switch.
Here's a (contrived) example:
Say you just typed the second-to-last line.
django.db.models.Q
has not been imported yet, so there will be errors on that line. There is no Quick Fix action available to importQ
(in this case, I believe it has to do with Django stub issues, but the point is any general case where a matching import is not detected).In this short example, it's obviously no problem to add an import for
Q
. But what if there are 700 lines aboveCompanyQuerySet
? Then the options are:It would be nice if it were possible to write out the manual import inline, then apply a refactoring action to move the import to module scope (i.e. "Move import to top of file").
Beta Was this translation helpful? Give feedback.
All reactions