Open nh916 opened 6 months ago
When writing
from pylint.interfaces import IAstroidChecker # type: ignore[attr-defined] # It is defined in pylint~=2
the combination of black
and isort
format the file on-save between
# black, 23.9.1: works
from pylint.interfaces import ( # type: ignore[attr-defined] # It is defined in pylint~=2
IAstroidChecker,
)
and:
# isort, 5.12.0 / 5.13.2: fails
from pylint.interfaces import \
IAstroidChecker # type: ignore[attr-defined] # It is defined in pylint~=2
Moreover, they compete endlessly with each other (one's format is not acceptable by the other).
Description:
When using
isort
in conjunction withmypy
, the placement of# type: ignore
comments on multi-line imports can lead to issues wheremypy
either doesn't recognize the ignore directive properly orisort
inadvertently moves the comment in a way that changes its intended effect. This can result inmypy
reporting errors for ignored imports.Issue:
The specific issue arises with multi-line imports that include a
# type: ignore
comment to bypassmypy
checks for a particular import statement.isort
, when reformatting import statements, can move the# type: ignore
comment in a way that changes its scope or applicability, potentially leading tomypy
errors or failing to ignore the intended line.Example
Before
isort
:After
isort
Formatting:In the example above, the
# type: ignore
comment is intended to ignore the entire import statement. However, afterisort
processes this code, the comment moves to a position where it only ignores theModuleA as RenamedA
line, causingmypy
to not recognize the ignore directive as intended for the entire import block.Current Remedy:
I could try putting a blanket ignore
# isort: skip
on the line, but then I'd lose the nice isort formatting features that make the code beautiful and readable.Requested Feature:
I would like to request a feature or configuration option in
isort
that provides more granular control over the placement of# type: ignore
comments in multi-line imports. Specifically, it would be helpful to:# type: ignore
comments as "anchored" to their original line or statement, preventingisort
from moving them during the sorting process.# type: ignore
comments maintain their position relative to the import statement they are intended to modify.This feature would greatly enhance the interoperability of
isort
withmypy
, especially in codebases that require specific type ignore directives for certain imports.Thank you for considering this feature request. I believe it would address a common pain point for developers working with both
isort
andmypy
in their projects.