isort
isort copied to clipboard
Inline sort chops import name
Given input:
class A:
def func(self):
# Avoid circular import
from .somewhere.utils import (
some_circular_func
)
Running isort results in:
class A:
def func(self):
# Avoid circular import
from .somewhere.utils import _circular_func
While the input is probably not valid syntax, it would be better for isort to reject it outright if it can't handle the case rather than to mangle the name of the import (which could easily be missed if the code wasn't checked afterwards).
I originally hit this via the VSCode Python extension, with a setup.cfg in the project, however it reproduces on the command line outside that directory (i.e: no configuration).
I'm using isort version 5.10.1 on Python 3.9.
Possibly related to this -- if the imported thing starts in column 1 then it is liable to be removed completely:
def func():
from sr.comp.cli.deploy import (
BOLD,
ENDC,
FAIL,
get_current_state,
get_deployments,
ref_compstate,
)
gets sorted to:
def func():
from sr.comp.cli.deploy import (
BOLD,
current_state,
get_deployments,
ref_compstate,
)
Note that two of the lines have been removed completely and a third has been mangled.
Expected:
from sr.comp.cli.deploy import (
BOLD,
ENDC,
FAIL,
get_current_state,
get_deployments,
ref_compstate,
)
This is seen using isort 5.12.0 on Python 3.10 and reproduces in the online demo UI.