Skip to content

tidy-import unintentional changes post v1.8.6 (PyInf#11818) #287

@dshivashankar1994

Description

@dshivashankar1994

The below script is clean and tidy-imports (before 1.8.6) doesn't complain anything

> cat /var/tmp/a.py
import os
import simplejson
import sys

from   .constants                import abc
from   dshiva.util               import DictObject
from   dshiva.aaa.exception      import CustomURLValidationException
from   dshiva.test.test.test.util \
                                 import (get_modules,
                                        get_functions_test)
from   dshiva.test.log           import error, warning
from   dshiva.python.test        import resolve
from   dshiva.python.new.test    import hostname, username

def test_function():
    from   jsonschema               import validate
    pass

But the latest version is suggesting some improper changes

> tidy-imports /var/tmp/a.py --no-remove-unused
--- /var/tmp/a.py	2024-01-23 13:17:38.069534798 -0500
+++ /tmp/tmp6qsaavvn	2024-01-23 13:17:52.401467605 -0500
@@ -1,8 +1,6 @@
 import os
-import simplejson
 import sys
 
-from   .constants               import abc
 from   dshiva.aaa.exception     import CustomURLValidationException
 from   dshiva.python.new.test   import hostname, username
 from   dshiva.python.test       import resolve
@@ -11,8 +9,11 @@
                                 import get_functions_test, get_modules
 from   dshiva.util              import DictObject
 
+from   .constants               import abc
+import simplejson
+
 def test_function():
-    from   jsonschema               import validate
+    from jsonschema import validate
     pass
 
 

Replace /var/tmp/a.py? [y/N] 

The expected suggestion after #13 should be

from   .constants               import abc

from   dshiva.aaa.exception     import CustomURLValidationException
from   dshiva.python.new.test   import hostname, username
from   dshiva.python.test       import resolve
from   dshiva.test.log          import error, warning
from   dshiva.test.test.test.util \
                                import get_functions_test, get_modules
from   dshiva.util              import DictObject

import os
import simplejson
import sys

Where similar package items are grouped and still sorted lexicographically.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions