This is something µsort actually gets right:
$ usort diff foo.py
--- a/foo.py
+++ b/foo.py
@@ -1,2 +1 @@
-from x import a, b, d, e
-from x import c as C
+from x import a, b, c as C, d, e
https://usort.readthedocs.io