You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using isort in conjunction with mypy, the placement of # type: ignore comments on multi-line imports can lead to issues where mypy either doesn't recognize the ignore directive properly or isort inadvertently moves the comment in a way that changes its intended effect. This can result in mypy reporting errors for ignored imports.
Issue:
The specific issue arises with multi-line imports that include a # type: ignore comment to bypass mypy 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 to mypy errors or failing to ignore the intended line.
Example
Before isort:
This comment correctly ignores the mypy issue with this package missing type hinting
After isort formats the import, it moves the mypy ignore typing comment with it and mypy now flags this import again as missing type hinting because it doesn't know that I am trying to ignore the typing on this package
In the example above, the # type: ignore comment is intended to ignore the entire import statement. However, after isort processes this code, the comment moves to a position where it only ignores the ModuleA as RenamedA line, causing mypy 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.
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:
Provide an option to treat # type: ignore comments as "anchored" to their original line or statement, preventing isort from moving them during the sorting process.
Ensure # 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 with mypy, 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 and mypy in their projects.
The text was updated successfully, but these errors were encountered:
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.The text was updated successfully, but these errors were encountered: