Skip to content

Removed "reportShadowedImports" check #10891

Merged
erictraut merged 2 commits intomainfrom
removeShadowedImports
Sep 8, 2025
Merged

Removed "reportShadowedImports" check #10891
erictraut merged 2 commits intomainfrom
removeShadowedImports

Conversation

@erictraut
Copy link
Collaborator

@erictraut erictraut commented Sep 4, 2025

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.
@erictraut erictraut requested a review from rchiodo September 4, 2025 02:59
@github-actions

This comment has been minimized.

Copy link
Collaborator

@rchiodo rchiodo left a comment

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
Copy link
Contributor

github-actions bot commented Sep 8, 2025

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) ...

@erictraut erictraut merged commit 7905b19 into main Sep 8, 2025
20 checks passed
@erictraut erictraut deleted the removeShadowedImports branch September 8, 2025 16:35
@rchiodo
Copy link
Collaborator

rchiodo commented Sep 15, 2025

@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
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
Collaborator

rchiodo commented Sep 15, 2025

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.

@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
Collaborator

rchiodo commented Sep 15, 2025

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

@luabud
Copy link
Member

luabud commented Sep 16, 2025

@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 @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.

christophgietl added a commit to christophgietl/trcks that referenced this pull request Oct 25, 2025
This check has been removed
(see microsoft/pyright#10891).
christophgietl added a commit to christophgietl/trcks that referenced this pull request Oct 25, 2025
This check has been removed
(see microsoft/pyright#10891).
phuongfi91 added a commit to NextGenContributions/.nitpick that referenced this pull request Dec 22, 2025
Due to upstream removal microsoft/pyright#10891

Signed-off-by: Phuong Nguyen <7949163+phuongfi91@users.noreply.github.com>
ngnpope added a commit to ngnpope/django-stubs that referenced this pull request Mar 18, 2026
ngnpope added a commit to ngnpope/django-stubs that referenced this pull request Mar 18, 2026
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