"Remove all unused imports" should not remove implicitly used pytest fixture imports #4902
Replies: 10 comments
-
Pylance isn't a linter (like pylint or ruff). Pylance is built on a type checker called pyright. The types of conditions that linters and type checkers detect are mostly distinct, but there is some overlap, such as with unused imports. For type checkers, there is a standard way (defined in PEP 484) to suppress an error on a line. You use the comment |
Beta Was this translation helpful? Give feedback.
-
Of these three, only If I'm in |
Beta Was this translation helpful? Give feedback.
-
The You will see the symbol "grayed out", but that's expected and should occur regardless of the |
Beta Was this translation helpful? Give feedback.
-
Ah, there was a bug in the diagnostic filtering code where it incorrectly filtered "UnusedCode" diagnostics when a bare |
Beta Was this translation helpful? Give feedback.
-
The user's request was some way to prevent the "Remove all unused imports" action from removing certain imports that are used but not in a way that Pylance recognizes. Specifically, in pytest if a test function has an argument with the same name as a fixture, that fixture will be automatically passed in at test-time, but we don't see it as a reference. Using @rchiodo, both this issue and #4083 are about inadvertently removing pytest fixture imports. Maybe the pytest support in Pylance could be extended to prevent "Remove all unused imports" from removing these imports? |
Beta Was this translation helpful? Give feedback.
-
Maybe? That would likely require special code in the Remove unused imports action to special case this scenario. |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
This behavior is unintended and due to a bug that will be fixed in the next release. It's not a solution to this problem. |
Beta Was this translation helpful? Give feedback.
-
Moving this issue to discussion as an enhancement request for comments and upvotes. |
Beta Was this translation helpful? Give feedback.
-
Created this discussion item related to this, to track the idea of supporting #noqa for skipping unused imports diagnostics: #5080 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Does the source.unusedImports action support keeping an unused import tagged with a comment? If so what does it support? For example we have pytest fixtures that we import which are flagged as unused
If I do remove all unused imports that import gets removed. I also tried using # noqa that some other linters support.
Beta Was this translation helpful? Give feedback.
All reactions