Removed "reportShadowedImports" check #10891
Conversation
…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.
This comment has been minimized.
This comment has been minimized.
rchiodo
left a comment
There was a problem hiding this comment.
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.
|
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, 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. |
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:
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. |
|
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. |
|
Or another idea is we just ship ruff itself with Pylance. |
|
@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 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. |
This check has been removed (see microsoft/pyright#10891).
This check has been removed (see microsoft/pyright#10891).
Due to upstream removal microsoft/pyright#10891 Signed-off-by: Phuong Nguyen <7949163+phuongfi91@users.noreply.github.com>
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:
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.