Automatically add missing imports when using "Optimize Imports"?


I'm continuously refactoring my code and one of the things that's a bit annoying with PyCharm is the inability of its "Optimize Imports" functionality to not add missing imports to a file to which I have just added code using imports that are still missing in the file.

You always have to separately execute the import command.

Is there a way to make this available as a single command?

BTW this could be an option under Settings..., next to Auto-Import: Optimize Imports, check box "Automatically add missing imports" or such.

Additional comment:

What could make life a lot easier would be that when pasting a (copied/cut) piece of code from one file into another, is that the editor would automatically take the imports linked in the source file to the target file. (this would actually apply to the whole family of IntelliJ products...)

Comments appreciated, though my QUESTION is primary.


Please sign in to leave a comment.