Closed fau-st closed 1 month ago
This is due to the fact that pylance is using a slightly-older version of pyright. Once pylance upgrades to the latest version, you will see the same error in both places.
Your code is using a variable in a type annotation, which is explicitly forbidden by the python typing spec. There was a bug in pyright where it didn't always report this error, and I recently fixed the bug.
Here's the correct way to define this type alias:
MyTypeAlias: TypeAlias = Literal[SomeEnum.ENUM_VALUE] | None
Or using Python 3.12 syntax:
type MyTypeAlias = Literal[SomeEnum.ENUM_VALUE] | None
Thank you very much for the quick answer :+1: I'm aware this snippet uses invalid constructs, it's from a third party library and I wanted to be sure where the error was coming from. Is CHANGELOG.md the right place to know about the pyright version shipped with pylance or can it be fetched somewhere else?
Environment data
Code Snippet
Repro Steps
pyright
(Playground )Expected behavior
Both tools report the same issues.
Actual behavior
pylance
doesn't report an issue butpyright
does. I tried to follow USING_WITH_PYRIGHT.md but I can't seem to find what's the difference between the tools.Revealed type is
"Literal[SomeEnum.ENUM_VALUE] | None"
forpylance
but"Unknown | None"
forpyright
(plus thereportInvalidTypeForm
error).It looks like
pylance
is able to infer that_ENUM_VALUE
is a litteral value.Logs
Trace logging
``` 2024-07-16 16:00:08.755 [info] (Client) Pylance async client (2024.7.1) started with python extension (2024.10.0) 2024-07-16 16:00:09.120 [info] [Info - 4:00:09 PM] (1616284) Pylance language server 2024.7.1 (pyright version 1.1.369, commit 1168be71) starting 2024-07-16 16:00:09.120 [info] [Info - 4:00:09 PM] (1616284) Server root directory: file:///local/home/fau-st/.vscode/extensions/ms-python.vscode-pylance-2024.7.1/dist 2024-07-16 16:00:09.124 [info] [Info - 4:00:09 PM] (1616284) Starting service instance "pyright_bug" 2024-07-16 16:00:09.147 [info] [Info - 4:00:09 PM] (1616284) Setting pythonPath for service "pyright_bug": "/local/home/fau-st/.pyenv/versions/3.12.0/bin/python" 2024-07-16 16:00:09.147 [info] [Info - 4:00:09 PM] (1616284) Setting environmentName for service "pyright_bug": "3.12.0 (global)" 2024-07-16 16:00:09.147 [info] [Info - 4:00:09 PM] (1616284) No include entries specified; assuming /local/home/fau-st/temp/pyright_bug 2024-07-16 16:00:09.148 [info] [Info - 4:00:09 PM] (1616284) Auto-excluding **/node_modules 2024-07-16 16:00:09.148 [info] [Info - 4:00:09 PM] (1616284) Auto-excluding **/__pycache__ 2024-07-16 16:00:09.148 [info] [Info - 4:00:09 PM] (1616284) Auto-excluding **/.* 2024-07-16 16:00:09.166 [info] [Info - 4:00:09 PM] (1616284) Assuming Python version 3.12.0.final.0 2024-07-16 16:00:09.203 [info] [Info - 4:00:09 PM] (1616284) No source files found. 2024-07-16 16:00:09.538 [info] [Info - 4:00:09 PM] (1616284) Background analysis(1) root directory: file:///local/home/fau-st/.vscode/extensions/ms-python.vscode-pylance-2024.7.1/dist 2024-07-16 16:00:09.540 [info] [Info - 4:00:09 PM] (1616284) Background analysis(1) started 2024-07-16 16:00:09.594 [info] [Info - 4:00:09 PM] (1616284) Indexer background runner(2) root directory: file:///local/home/fau-st/.vscode/extensions/ms-python.vscode-pylance-2024.7.1/dist (index) 2024-07-16 16:00:09.594 [info] [Info - 4:00:09 PM] (1616284) Indexing(2) started 2024-07-16 16:00:09.838 [info] [Info - 4:00:09 PM] (1616284) scanned(2) 13 files over 1 exec env 2024-07-16 16:00:10.014 [info] [Info - 4:00:10 PM] (1616284) indexed(2) 3 files over 1 exec env 2024-07-16 16:00:10.022 [info] [Info - 4:00:10 PM] (1616284) Indexing finished(2). 2024-07-16 16:00:22.731 [info] [Info - 4:00:22 PM] (1616284) Found 1 source file 2024-07-16 16:01:16.499 [info] [Info - 4:01:16 PM] (1616284) Starting service instance "