'optimize imports' entirely unhelpful

I've been having a lot of trouble getting the Optimize Imports functionality to be helpful. My team follows the PEP8 import ordering, with imports sorted into three groups, and we also sort alphabetically within the groups.

Apparently, the "optimize imports" (http://www.jetbrains.com/pycharm/webhelp/optimizing-imports.html) command should do the grouping for me. However, it doesn't work right:

Correct import formatting
import datetime # Standard lib

import numpy # External

import my_module # local
import zz_module # local

Pycharm consistently finds some third-party import to put in the wrong place, for example, numpy, and also doesn't care when imports inside a group are in the wrong order:

"optimize imports" import formatting
import datetime # Standard lib
import numpy # External, in the wrong place

import zz_module # local
import my_module # local; optimize_imports does not fix mis-alphabetized imports

The incorrect grouping seems like a bug, and the lack of alphabetization seems like a missing feature. Together, they make the "optimize imports" feature entirely unhelpful for my team.
Am I missing something? If so, where can I report the bug/request the feature?

I've been having some trouble too, but I found out the problem was that the environment setup was confusing Pycharm, making it treat my local library as a third-party library... I eventually managed to make it work. Alphabetical order works fine for me too. Try checking out your project dependencies and installed libraries, make a new virtualenv from scratch, I don't know...


I wanted to add a comment that this is still a problem. I get hit in code review if I forget to reorder imports after doing a Reformat Code. I can turn off Optimize Imports but I like the reformatting it does except for not breaking out imports properly.


Hello @Richard Haussmann ,

I have tested it in 2020.3 and the imports are optimized exactly how you would expect it.   Could you please provide me with a screencast example, or a code example before and after optimization, and logs folder zipped from ***Help | Collect logs and Diagnostic Data*** ? Please upload it to the FTP

https://uploads.jetbrains.com/ and please let me know the filename. 


Please sign in to leave a comment.