Skip to content

Removed "reportShadowedImports" check - #10891

Merged
Eric Traut (erictraut) merged 2 commits into
mainfrom
removeShadowedImports
Sep 8, 2025
Merged

Eric Traut (erictraut) merged 2 commits into
mainfrom
removeShadowedImports

Conversation

@erictraut

@erictraut Eric Traut (erictraut) commented Sep 4, 2025 •

Copy link
Copy Markdown
Collaborator

Removed "reportShadowedImports" check and associated "renameShadowedFile" action. This feature is off by default in pyright although enabled by default in pylance.

It's problematic for a number of reasons:

  1. It's not a type checking feature. It's a linting feature, so it really don't belong in a type checker.
  2. The implementation is very problematic because it introduces an inverted dependency. Namely, it causes the Checker to depend on a language server provider and source mapper.
  3. This dependency results in significant performance problems when the check is enabled.

I'd prefer to leave this feature out permanently and ask users to rely on a linter if they want to enable a check like this. If the pylance team feels that this is really important to retain, then it should be reimplemented in a way that doesn't introduce bad dependencies and performance problems. Perhaps it should be a pylance-specific feature that is not implemented in pyright.

…ile" action. This feature is off by default in pyright although enabled by default in pylance.

It's problematic for a number of reasons:
1. It's not a type checking feature. It's a linting feature, so it really don't belong in a type checker.
2. The implementation is very problematic because it introduces an inverted dependency. Namely, it causes the Checker to depend on a language server provider and source mapper.
3. This dependency results in significant performance problems when the check is enabled.

I'd prefer to leave this feature out permanently and ask users to rely on a linter if they want to enable a check like this. If the pylance team feels that this is really important to retain, then it should be reimplemented in a way that doesn't introduce bad dependencies and performance problems.
@github-actions

This comment has been minimized.

@rchiodo Rich Chiodo (rchiodo) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me. This error doesn't show up at all in our telemetry so I don't think it's a common problem.

@github-actions

github-actions Bot commented Sep 8, 2025

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

sympy (https://github.com/sympy/sympy)
+   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:173:44 - error: Cannot access attribute "expand" for class "Basic"
+     Attribute "expand" is unknown (reportAttributeAccessIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:420:38 - error: Argument of type "int | Any | Unknown | Expr" cannot be assigned to parameter "expr" of type "Expr" in function "make_args"
+   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:420:38 - error: Argument of type "Unknown | Expr | Literal[0]" cannot be assigned to parameter "expr" of type "Expr" in function "make_args"
-     Type "int | Any | Unknown | Expr" is not assignable to type "Expr"
+     Type "Unknown | Expr | Literal[0]" is not assignable to type "Expr"
-       "int" is not assignable to "Expr" (reportArgumentType)
+       "Literal[0]" is not assignable to "Expr" (reportArgumentType)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:499:19 - error: Operator "**" not supported for types "Unknown | Basic" and "Literal[2]"
-     Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:500:19 - error: Operator "*" not supported for types "Unknown | Basic" and "Unknown | Basic"
-     Operator "*" not supported for types "Basic" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:501:19 - error: Operator "**" not supported for types "Unknown | Basic" and "Literal[2]"
-     Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:528:23 - error: Operator "+" not supported for types "Generator[Unknown | int, Unknown, None] | list[Unknown | int]" and "list[Unknown | int]"
+   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:528:23 - error: Operator "+" not supported for types "Generator[Unknown | Literal[1], Unknown, None] | list[Unknown | Literal[1]]" and "list[Unknown | int]"
-     Operator "+" not supported for types "Generator[Unknown | int, Unknown, None]" and "list[Unknown | int]" (reportOperatorIssue)
+     Operator "+" not supported for types "Generator[Unknown | Literal[1], Unknown, None]" and "list[Unknown | int]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:564:42 - error: Operator "*" not supported for types "int" and "Unknown | Basic"
-     Operator "*" not supported for types "int" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:564:50 - error: Operator "*" not supported for types "Expr" and "Unknown | Basic"
-     Operator "*" not supported for types "Expr" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:720:42 - error: Operator "**" not supported for types "Unknown | Basic" and "Literal[2]"
-     Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:730:19 - error: Operator "**" not supported for types "Unknown | Basic" and "Literal[2]"
-     Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:731:19 - error: Operator "**" not supported for types "Unknown | Basic" and "Literal[2]"
-     Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:732:19 - error: Operator "**" not supported for types "Unknown | Basic" and "Literal[2]"
-     Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:809:47 - error: Operator "**" not supported for types "Unknown | Basic" and "Literal[2]"
-     Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:836:26 - error: Operator "**" not supported for types "Unknown | Basic" and "Literal[2]"
-     Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:837:22 - error: Operator "*" not supported for types "Unknown | Basic" and "Unknown | Basic"
-     Operator "*" not supported for types "Basic" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:838:36 - error: Operator "*" not supported for types "int | Any | Unknown" and "Unknown | Basic"
-     Operator "*" not supported for types "int" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:838:42 - error: Operator "*" not supported for types "Unknown | Basic" and "Unknown | Basic"
-     Operator "*" not supported for types "Basic" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:838:51 - error: Operator "*" not supported for types "int | Any | Unknown" and "Unknown | Basic"
-     Operator "*" not supported for types "int" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:838:57 - error: Operator "*" not supported for types "Unknown | Basic" and "Unknown | Basic"
-     Operator "*" not supported for types "Basic" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:838:66 - error: Operator "*" not supported for types "Unknown | Basic" and "Unknown | Basic"
-     Operator "*" not supported for types "Basic" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:840:53 - error: Operator "*" not supported for types "Unknown | Basic" and "Unknown | Basic"
-     Operator "*" not supported for types "Basic" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:849:18 - error: Operator "**" not supported for types "Unknown | Basic" and "Literal[2]"
-     Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:851:22 - error: Operator "**" not supported for types "Unknown | Basic" and "Literal[2]"
-     Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:860:22 - error: Operator "*" not supported for types "Unknown | Basic" and "Unknown | Basic"
-     Operator "*" not supported for types "Basic" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:860:36 - error: Operator "*" not supported for types "Unknown | Basic" and "Unknown | Basic"
-     Operator "*" not supported for types "Basic" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:862:27 - error: Operator "**" not supported for types "Unknown | Basic" and "Literal[2]"
-     Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:863:27 - error: Operator "*" not supported for types "Unknown | Basic" and "Unknown | Basic"
-     Operator "*" not supported for types "Basic" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:864:27 - error: Operator "*" not supported for types "Unknown | Basic" and "Unknown | Basic"
-     Operator "*" not supported for types "Basic" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:865:27 - error: Operator "**" not supported for types "Unknown | Basic" and "Literal[2]"
-     Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:866:27 - error: Operator "*" not supported for types "Unknown | Basic" and "Unknown | Basic"
-     Operator "*" not supported for types "Basic" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:867:27 - error: Operator "**" not supported for types "Unknown | Basic" and "Literal[2]"
-     Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:871:24 - error: Operator "**" not supported for types "Unknown | Basic" and "Literal[2]"
-     Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:872:24 - error: Operator "**" not supported for types "Unknown | Basic" and "Literal[2]"
-     Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:873:24 - error: Operator "**" not supported for types "Unknown | Basic" and "Literal[2]"
-     Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:874:24 - error: Operator "*" not supported for types "Unknown | Basic" and "Unknown | Basic"
-     Operator "*" not supported for types "Basic" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:875:24 - error: Operator "*" not supported for types "Unknown | Basic" and "Unknown | Basic"
-     Operator "*" not supported for types "Basic" and "Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:876:24 - error: Operator "*" not supported for types "Unknown | Basic" and "Unknown | Basic"
-     Operator "*" not supported for types "Basic" and "Basic" (reportOperatorIssue)

... (truncated 576 lines) ...

@rchiodo

Copy link
Copy Markdown
Collaborator

Eric Traut (@erictraut), we'd like to reimplement this. Are you okay with Pylance having different diagnostics than Pyright?

I could reimplement it in Pyright but make it much simpler (just have the checker verify the file name isn't one of a known set of system modules). Or we can do the same in Pylance instead but then our errors would diverge.

@erictraut

Copy link
Copy Markdown
Collaborator Author

Are you okay with Pylance having different diagnostics than Pyright?

That's up to you and the pylance team to decide. It's going to create usability issues, so it's not the approach I would personally recommend.

Some questions I think the pylance team should consider before going this route:

  1. Do you agree with my assertion that this is a linter-style check, as opposed to check that belongs in a type checker?
  2. Do you want the pylance language server to offer linter-style checks? Historically, it has avoided this and left such checks up to dedicated linters like pylint and ruff.
  3. If you want pylance to be in the business of reporting linter-style issues, what principle will you use for deciding which linter checks to include and which are out of scope? Is there something special about this particular check that makes it different from other linter-style checks?

If you end up implementing this in pylance, please consider how developers who use pylance in VS Code and pyright + ruff in their CI can get consistent diagnostics in both places.

@rchiodo

Copy link
Copy Markdown
Collaborator

I agree that this is a linter style check and should be part of a linter, but I'm not sure others will know or care what the difference is. I believe we just want it there for newbies and newbies aren't going to have pylint/ruff setup. We have a hard enough time explaining to people just starting out that they need to install a 'Python' extension.

Luciana Abud (@luabud) do you have any thoughts?

Maybe an alternative here is to finish TSP and get 'Ty' shipping with Pylance. It would show this error because it runs all the diagnostics that ruff does I believe.

@rchiodo

Copy link
Copy Markdown
Collaborator

Or another idea is we just ship ruff itself with Pylance.

@luabud

Copy link
Copy Markdown
Member

Rich Chiodo (@rchiodo) agreed it's a linter style check, but it's a different one since it's not meant to maintain consistency on the code base, it's to prevent users from making unintentional mistakes.

The example we saw happen was a user who named some module after a standard library module name accidentally (I believe it was copy.py), which was indirectly getting imported. Unfortunately the module was written as a script to delete a bunch of files, so when they ran their project, it accidentally called that script and wiped out some files. It's an easy mistake to make when you don't understand how the Python import system works.

I also agree with you that newbies aren't going to have linters set up. I guess the other option would be to implement this on the Python extension side? Maybe Karthik Nadig (@karthiknadig) would disagree but from my perspective it makes sense to have a "set up" warning like this coming from the Python extension, rather than treating this as a linter rule.

Christoph Gietl (christophgietl) added a commit to christophgietl/trcks that referenced this pull request Oct 25, 2025
This check has been removed
(see microsoft/pyright#10891).
Christoph Gietl (christophgietl) added a commit to christophgietl/trcks that referenced this pull request Oct 25, 2025
This check has been removed
(see microsoft/pyright#10891).
Phuong Nguyen (phuongfi91) added a commit to NextGenContributions/.nitpick that referenced this pull request Dec 22, 2025
Nick Pope (ngnpope) added a commit to ngnpope/django-stubs that referenced this pull request Mar 18, 2026
Nick Pope (ngnpope) added a commit to ngnpope/django-stubs that referenced this pull request Mar 18, 2026
Nick Pope (ngnpope) added a commit to ngnpope/django-stubs that referenced this pull request Mar 31, 2026
Nick Pope (ngnpope) added a commit to typeddjango/django-stubs that referenced this pull request Mar 31, 2026
* Remove `Union` typing in the plugin

As Python 3.10 is the minimum supported version, we can use the PEP 604
syntax instead of `typing.Union`.

* Remove references to `Union` in comments and docstrings

As Python 3.10 is the minimum supported version, we can use the PEP 604
syntax instead of `typing.Union`.

* Use `from __future__ import annotations` in the plugin

This allows us to postpone evaulation of annotations so that we don't
need to manually stringify some annotations. It also makes it possible
to avoid importing things at runtime that are only used for type
checking. As a bonus, it's closer to the Python 3.14 behavour so, when
3.14 becomes the minimum version, we'll be able to simply remove the
future import without any other changes.

* Use `from __future__ import annotations` in ext

* Use `from __future__ import annotations` in scripts

* Use `from __future__ import annotations` in tests

* Enforce use of `from __future__ import annotations`

* fixup! Use `from __future__ import annotations` in tests

* Enable `strict_equality_for_none` mypy option

* Enable `allow_redefinition_new` mypy option

This is to become the default at some point beyond mypy v2.0

It will replace the exising `allow_redefinition` in v2.0

See python/mypy#20726

* Enable `fixed_format_cache` mypy option

This is to become the default in mypy v1.20.

* Remove obsolete `reportShadowedImports` option for pyright

See microsoft/pyright#10891
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants