microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.7k stars 769 forks source link

False Positive for `covariant` when using `T | None` #4613

Open Why-not-now opened 1 year ago

Why-not-now commented 1 year ago

Environment data

Code Snippet

from typing import Generic, TypeVar, Protocol

T = TypeVar("T")
T_co = TypeVar("T_co", covariant=True)

class FalsePositive(Generic[T], Protocol):
    var: tuple[T | None, T | None]

class Positive(Generic[T_co], Protocol):
    var: tuple[T_co | None, T_co | None]

Expected behavior

Only the class Positive to give a warning that Type variable "T_co" used in generic protocol "Positive" should be invariant, just like mypy.

Actual behavior

Opposite is true, class Positive does not give a warning. Class FalsePositive gives a warning that Type variable "T" used in generic protocol "FalsePositive" should be covariant.

Logs

2023-07-16 10:00:36.842 [info] [Info  - 10:00:36 AM] (6404) Pylance language server 2023.7.20 (pyright 74d8f3c4) starting
2023-07-16 10:00:36.845 [info] [Info  - 10:00:36 AM] (6404) Server root directory: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist
2023-07-16 10:00:37.137 [info] [Info  - 10:00:37 AM] (6404) Starting service instance "<default>"
2023-07-16 10:00:37.255 [info] (6404) No pyproject.toml file found.
2023-07-16 10:00:37.255 [info] [Info  - 10:00:37 AM] (6404) Setting pythonPath for service "<default>": "C:\Users\USER\AppData\Local\Programs\Python\Python311\python.exe"
2023-07-16 10:00:37.431 [info] [Warn  - 10:00:37 AM] (6404) stubPath typings is not a valid directory.
2023-07-16 10:00:41.062 [info] [Info  - 10:00:41 AM] (6404) Assuming Python version 3.11
2023-07-16 10:00:41.062 [info] (6404) Assuming Python platform Windows
2023-07-16 10:00:46.480 [info] [Info  - 10:00:46 AM] (6404) Search paths for <default>
2023-07-16 10:00:46.481 [info] [Info  - 10:00:46 AM] (6404)   c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib
2023-07-16 10:00:46.482 [info] [Info  - 10:00:46 AM] (6404)   typings
2023-07-16 10:00:46.482 [info] [Info  - 10:00:46 AM] (6404)   c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stubs\...
2023-07-16 10:00:46.482 [info] [Info  - 10:00:46 AM] (6404)   c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\bundled\stubs
2023-07-16 10:00:46.483 [info] [Info  - 10:00:46 AM] (6404)   c:\Users\USER\AppData\Local\Programs\Python\Python311\DLLs
2023-07-16 10:00:46.483 [info] [Info  - 10:00:46 AM] (6404)   c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib
2023-07-16 10:00:46.483 [info] [Info  - 10:00:46 AM] (6404)   c:\Users\USER\AppData\Local\Programs\Python\Python311
2023-07-16 10:00:46.483 [info] [Info  - 10:00:46 AM] (6404)   c:\Users\USER\AppData\Roaming\Python\Python311\site-packages
2023-07-16 10:00:46.484 [info] [Info  - 10:00:46 AM] (6404)   c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages
2023-07-16 10:00:46.484 [info] [Info  - 10:00:46 AM] (6404)   c:\Users\USER\Documents\Generic folder\coding\python\higgs_solver\src
2023-07-16 10:00:46.484 [info] [Info  - 10:00:46 AM] (6404)   c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32
2023-07-16 10:00:46.484 [info] [Info  - 10:00:46 AM] (6404)   c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32\lib
2023-07-16 10:00:46.484 [info] [Info  - 10:00:46 AM] (6404)   c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\pythonwin
2023-07-16 10:00:46.485 [info] [Info  - 10:00:46 AM] (6404) Adding fs watcher for library directories:
 C:\Users\USER\AppData\Local\Programs\Python\Python311\DLLs
C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib
C:\Users\USER\AppData\Local\Programs\Python\Python311
C:\Users\USER\AppData\Roaming\Python\Python311\site-packages
C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages
C:\Users\USER\Documents\Generic folder\coding\python\higgs_solver\src
C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32
C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32\lib
C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\Pythonwin
2023-07-16 10:00:46.491 [info] (6404) Searching for source files
2023-07-16 10:00:46.494 [info] [Info  - 10:00:46 AM] (6404) No source files found.
2023-07-16 10:00:47.296 [info] (6404) [IDX(FG)] index libraries  (index) ...
2023-07-16 10:00:47.297 [info] (6404) [IDX(FG)]   read stdlib indices (283ms)
2023-07-16 10:00:47.297 [info] (6404) [IDX(FG)] index libraries  (index) [succeed] (294ms)
2023-07-16 10:00:47.297 [info] [Info  - 10:00:47 AM] (6404) Background analysis(1) root directory: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist
2023-07-16 10:00:47.297 [info] [Info  - 10:00:47 AM] (6404) Background analysis(1) started
2023-07-16 10:00:47.297 [info] (6404) Background analysis message: setConfigOptions
2023-07-16 10:00:47.297 [info] (6404) Background analysis message: setImportResolver
2023-07-16 10:00:47.297 [info] (6404) Background analysis message: ensurePartialStubPackages
2023-07-16 10:00:47.298 [info] (6404) Background analysis message: setConfigOptions
2023-07-16 10:00:47.298 [info] (6404) Background analysis message: setTrackedFiles
2023-07-16 10:00:47.298 [info] (6404) Background analysis message: markAllFilesDirty
2023-07-16 10:00:47.298 [info] (6404) No pyproject.toml file found.
2023-07-16 10:00:47.298 [info] [Info  - 10:00:47 AM] (6404) Setting pythonPath for service "<default>": "C:\Users\USER\AppData\Local\Programs\Python\Python311\python.exe"
2023-07-16 10:00:47.298 [info] [Warn  - 10:00:47 AM] (6404) stubPath typings is not a valid directory.
2023-07-16 10:00:49.951 [info] [Info  - 10:00:49 AM] (6404) Assuming Python version 3.11
2023-07-16 10:00:49.966 [info] (6404) Assuming Python platform Windows
2023-07-16 10:00:52.446 [info] [Info  - 10:00:52 AM] (6404) Search paths for <default>
2023-07-16 10:00:52.447 [info] [Info  - 10:00:52 AM] (6404)   c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib
2023-07-16 10:00:52.447 [info] [Info  - 10:00:52 AM] (6404)   typings
2023-07-16 10:00:52.447 [info] [Info  - 10:00:52 AM] (6404)   c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stubs\...
2023-07-16 10:00:52.447 [info] [Info  - 10:00:52 AM] (6404)   c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\bundled\stubs
2023-07-16 10:00:52.447 [info] [Info  - 10:00:52 AM] (6404)   c:\Users\USER\AppData\Local\Programs\Python\Python311\DLLs
2023-07-16 10:00:52.447 [info] [Info  - 10:00:52 AM] (6404)   c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib
2023-07-16 10:00:52.448 [info] [Info  - 10:00:52 AM] (6404)   c:\Users\USER\AppData\Local\Programs\Python\Python311
2023-07-16 10:00:52.448 [info] [Info  - 10:00:52 AM] (6404)   c:\Users\USER\AppData\Roaming\Python\Python311\site-packages
2023-07-16 10:00:52.448 [info] [Info  - 10:00:52 AM] (6404)   c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages
2023-07-16 10:00:52.448 [info] [Info  - 10:00:52 AM] (6404)   c:\Users\USER\Documents\Generic folder\coding\python\higgs_solver\src
2023-07-16 10:00:52.448 [info] [Info  - 10:00:52 AM] (6404)   c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32
2023-07-16 10:00:52.448 [info] [Info  - 10:00:52 AM] (6404)   c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32\lib
2023-07-16 10:00:52.448 [info] [Info  - 10:00:52 AM] (6404)   c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\pythonwin
2023-07-16 10:00:52.448 [info] [Info  - 10:00:52 AM] (6404) Adding fs watcher for library directories:
 C:\Users\USER\AppData\Local\Programs\Python\Python311\DLLs
C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib
C:\Users\USER\AppData\Local\Programs\Python\Python311
C:\Users\USER\AppData\Roaming\Python\Python311\site-packages
C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages
C:\Users\USER\Documents\Generic folder\coding\python\higgs_solver\src
C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32
C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32\lib
C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\Pythonwin
2023-07-16 10:00:52.451 [info] (6404) Searching for source files
2023-07-16 10:00:52.452 [info] [Info  - 10:00:52 AM] (6404) No source files found.
2023-07-16 10:00:52.521 [info] (6404) [IDX(FG)] index libraries  (index) ...
2023-07-16 10:00:52.521 [info] (6404) [IDX(FG)]   read stdlib indices (0ms)
2023-07-16 10:00:52.528 [info] (6404) [IDX(FG)] index libraries  (index) [succeed] (7ms)
2023-07-16 10:00:53.210 [info] (6404) [FG] parsing: Untitled-1 (677ms)
2023-07-16 10:00:54.809 [info] (6404) [FG] parsing: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\builtins.pyi [fs read 5ms] (1597ms)
2023-07-16 10:00:55.343 [info] (6404) [FG] binding: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\builtins.pyi (387ms)
2023-07-16 10:00:55.343 [info] (6404) [FG] binding: Untitled-1 (1ms)
2023-07-16 10:00:55.345 [info] (6404) Background analysis message: setFileOpened
2023-07-16 10:00:55.345 [info] (6404) Background analysis message: setConfigOptions
2023-07-16 10:00:55.345 [info] (6404) Background analysis message: setImportResolver
2023-07-16 10:00:55.345 [info] (6404) Background analysis message: ensurePartialStubPackages
2023-07-16 10:00:55.345 [info] (6404) Background analysis message: setConfigOptions
2023-07-16 10:00:55.345 [info] (6404) Background analysis message: setTrackedFiles
2023-07-16 10:00:55.347 [info] (6404) Background analysis message: markAllFilesDirty
2023-07-16 10:00:55.347 [info] (6404) Background inlayHint message
2023-07-16 10:00:55.347 [info] (6404) [BG(1)] getInlayHints range 0:0 - 13:0 at Untitled-1 ...
2023-07-16 10:00:55.347 [info] (6404) [BG(1)]   parsing: Untitled-1 (1055ms)
2023-07-16 10:00:55.347 [info] (6404) [BG(1)]   parsing: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\builtins.pyi [fs read 21ms] (1438ms)
2023-07-16 10:00:55.653 [info] (6404) [BG(1)]   binding: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\builtins.pyi (360ms)
2023-07-16 10:00:55.654 [info] (6404) [BG(1)]   binding: Untitled-1 (1ms)
2023-07-16 10:00:55.655 [info] (6404) [BG(1)] getInlayHints range 0:0 - 13:0 at Untitled-1 (3036ms)
2023-07-16 10:00:55.655 [info] [Info  - 10:00:55 AM] (6404) [BG(1)] Long operation: getInlayHints range 0:0 - 13:0 at Untitled-1 (3036ms)
2023-07-16 10:00:55.656 [info] (6404) Background analysis message: getSemanticTokens full
2023-07-16 10:00:56.321 [info] (6404) [BG(1)] getSemanticTokens full at Untitled-1 ...
2023-07-16 10:00:56.321 [info] (6404) [BG(1)]   parsing: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\typing.pyi [fs read 1ms] (553ms)
2023-07-16 10:00:56.556 [info] (6404) [BG(1)]   binding: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\typing.pyi (79ms)
2023-07-16 10:00:56.556 [info] (6404) [BG(1)]   parsing: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\typing_extensions.pyi [fs read 1ms] (22ms)
2023-07-16 10:00:56.557 [info] (6404) [BG(1)]   binding: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\typing_extensions.pyi (55ms)
2023-07-16 10:00:56.805 [info] (6404) [BG(1)]   parsing: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi [fs read 1ms] (203ms)
2023-07-16 10:00:56.891 [info] (6404) [BG(1)]   binding: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi (69ms)
2023-07-16 10:00:56.943 [info] (6404) [BG(1)]   parsing: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\types.pyi [fs read 1ms] (100ms)
2023-07-16 10:00:56.960 [info] (6404) [BG(1)]   binding: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\types.pyi (18ms)
2023-07-16 10:00:57.062 [info] (6404) [BG(1)]   parsing: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\abc.pyi [fs read 1ms] (4ms)
2023-07-16 10:00:57.062 [info] (6404) [BG(1)]   binding: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\abc.pyi (2ms)
2023-07-16 10:00:57.608 [info] (6404) [BG(1)] getSemanticTokens full at Untitled-1 (1483ms)
2023-07-16 10:00:57.609 [info] (6404) Background analysis message: getSemanticTokens range
2023-07-16 10:00:57.609 [info] (6404) [BG(1)] getSemanticTokens range 0:0 - 13:0 at Untitled-1 (37ms)
2023-07-16 10:00:57.609 [info] (6404) Background analysis message: analyze
2023-07-16 10:00:57.954 [info] (6404) [BG(1)] analyzing: Untitled-1 ...
2023-07-16 10:00:57.955 [info] (6404) [BG(1)]   checking: Untitled-1 ...
2023-07-16 10:00:57.955 [info] (6404) [BG(1)]     parsing: c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\typing.py [fs read 2ms] (680ms)
2023-07-16 10:00:57.955 [info] [Info  - 10:00:57 AM] (6404) Could not import '_typing' in file 'c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\typing.py'
2023-07-16 10:00:57.955 [info] [Info  - 10:00:57 AM] (6404)   Looking in stubPath 'typings'
2023-07-16 10:00:57.955 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve stub package using root path 'typings'
2023-07-16 10:00:57.955 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve using root path 'typings'
2023-07-16 10:00:57.989 [info] [Info  - 10:00:57 AM] (6404)   Finding python search paths
2023-07-16 10:00:57.990 [info] [Info  - 10:00:57 AM] (6404)   Executing interpreter: 'C:\Users\USER\AppData\Local\Programs\Python\Python311\python.exe'
2023-07-16 10:00:57.991 [info] [Info  - 10:00:57 AM] (6404)   Skipping 'C:\Users\USER\AppData\Local\Programs\Python\Python311\python311.zip' because it is not a valid directory
2023-07-16 10:00:57.992 [info] [Info  - 10:00:57 AM] (6404)   Received 9 paths from interpreter
2023-07-16 10:00:57.993 [info] [Info  - 10:00:57 AM] (6404)     C:\Users\USER\AppData\Local\Programs\Python\Python311\DLLs
2023-07-16 10:00:57.993 [info] [Info  - 10:00:57 AM] (6404)     C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib
2023-07-16 10:00:57.993 [info] [Info  - 10:00:57 AM] (6404)     C:\Users\USER\AppData\Local\Programs\Python\Python311
2023-07-16 10:00:57.993 [info] [Info  - 10:00:57 AM] (6404)     C:\Users\USER\AppData\Roaming\Python\Python311\site-packages
2023-07-16 10:00:57.994 [info] [Info  - 10:00:57 AM] (6404)     C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages
2023-07-16 10:00:57.994 [info] [Info  - 10:00:57 AM] (6404)     C:\Users\USER\Documents\Generic folder\coding\python\higgs_solver\src
2023-07-16 10:00:57.994 [info] [Info  - 10:00:57 AM] (6404)     C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32
2023-07-16 10:00:57.994 [info] [Info  - 10:00:57 AM] (6404)     C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32\lib
2023-07-16 10:00:57.994 [info] [Info  - 10:00:57 AM] (6404)     C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\Pythonwin
2023-07-16 10:00:57.995 [info] [Info  - 10:00:57 AM] (6404)   Looking in python search path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\DLLs'
2023-07-16 10:00:57.995 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve stub package using root path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\DLLs'
2023-07-16 10:00:57.995 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve using root path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\DLLs'
2023-07-16 10:00:57.995 [info] [Info  - 10:00:57 AM] (6404)   Looking in python search path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib'
2023-07-16 10:00:57.995 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve stub package using root path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib'
2023-07-16 10:00:57.995 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve using root path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib'
2023-07-16 10:00:57.995 [info] [Info  - 10:00:57 AM] (6404)   Looking in python search path 'c:\Users\USER\AppData\Local\Programs\Python\Python311'
2023-07-16 10:00:57.995 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve stub package using root path 'c:\Users\USER\AppData\Local\Programs\Python\Python311'
2023-07-16 10:00:57.995 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve using root path 'c:\Users\USER\AppData\Local\Programs\Python\Python311'
2023-07-16 10:00:57.995 [info] [Info  - 10:00:57 AM] (6404)   Looking in python search path 'c:\Users\USER\AppData\Roaming\Python\Python311\site-packages'
2023-07-16 10:00:57.996 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve stub package using root path 'c:\Users\USER\AppData\Roaming\Python\Python311\site-packages'
2023-07-16 10:00:57.996 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve using root path 'c:\Users\USER\AppData\Roaming\Python\Python311\site-packages'
2023-07-16 10:00:57.996 [info] [Info  - 10:00:57 AM] (6404)   Looking in python search path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages'
2023-07-16 10:00:57.996 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve stub package using root path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages'
2023-07-16 10:00:57.996 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve using root path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages'
2023-07-16 10:00:57.996 [info] [Info  - 10:00:57 AM] (6404)   Looking in python search path 'c:\Users\USER\Documents\Generic folder\coding\python\higgs_solver\src'
2023-07-16 10:00:57.997 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve stub package using root path 'c:\Users\USER\Documents\Generic folder\coding\python\higgs_solver\src'
2023-07-16 10:00:57.997 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve using root path 'c:\Users\USER\Documents\Generic folder\coding\python\higgs_solver\src'
2023-07-16 10:00:57.998 [info] [Info  - 10:00:57 AM] (6404)   Looking in python search path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32'
2023-07-16 10:00:57.998 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve stub package using root path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32'
2023-07-16 10:00:57.998 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve using root path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32'
2023-07-16 10:00:57.998 [info] [Info  - 10:00:57 AM] (6404)   Looking in python search path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32\lib'
2023-07-16 10:00:57.998 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve stub package using root path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32\lib'
2023-07-16 10:00:57.998 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve using root path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32\lib'
2023-07-16 10:00:57.998 [info] [Info  - 10:00:57 AM] (6404)   Looking in python search path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\pythonwin'
2023-07-16 10:00:57.999 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve stub package using root path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\pythonwin'
2023-07-16 10:00:57.999 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve using root path 'c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\pythonwin'
2023-07-16 10:00:57.999 [info] [Info  - 10:00:57 AM] (6404)   Looking in bundled stubs path 'c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\bundled\stubs'
2023-07-16 10:00:57.999 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve stub package using root path 'c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\bundled\stubs'
2023-07-16 10:00:57.999 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve using root path 'c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\bundled\stubs'
2023-07-16 10:00:57.999 [info] [Info  - 10:00:57 AM] (6404)   Looking for typeshed stdlib path
2023-07-16 10:00:58.000 [info] [Info  - 10:00:57 AM] (6404)   Looking for typeshed stdlib path
2023-07-16 10:00:58.000 [info] [Info  - 10:00:57 AM] (6404)   Attempting to resolve using root path 'c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib'
2023-07-16 10:00:58.000 [info] [Info  - 10:00:57 AM] (6404)   Typeshed path not found
2023-07-16 10:00:58.001 [info] [Info  - 10:00:58 AM] (6404)   Looking for typeshed third-party path
2023-07-16 10:00:58.001 [info] [Info  - 10:00:58 AM] (6404)   Looking for typeshed stubs path
2023-07-16 10:00:58.002 [info] [Info  - 10:00:58 AM] (6404)   Typeshed path not found
2023-07-16 10:00:58.183 [info] (6404) [BG(1)]     binding: c:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\typing.py (167ms)
2023-07-16 10:00:58.183 [info] (6404) [BG(1)]   checking: Untitled-1 (950ms)
2023-07-16 10:00:58.183 [info] (6404) [BG(1)] analyzing: Untitled-1 (951ms)
2023-07-16 10:00:58.333 [info] (6404) Background analysis message: resumeAnalysis
2023-07-16 10:01:05.865 [info] (6404) Loading ONNX runtime...
2023-07-16 10:01:05.871 [info] (6404) Loaded ONNX runtime. Creating IntelliCode session...
2023-07-16 10:01:08.219 [info] 2023-07-16 10:01:08.215913 [I:onnxruntime:, inference_session.cc:263 operator()] Flush-to-zero and denormal-as-zero are off

2023-07-16 10:01:08.220 [info] 2023-07-16 10:01:08.218723 [I:onnxruntime:, inference_session.cc:271 ConstructorCommon] Creating and using per session threadpools since use_per_session_threads_ is true

2023-07-16 10:01:08.221 [info] 2023-07-16 10:01:08.219757 [I:onnxruntime:, inference_session.cc:292 ConstructorCommon] Dynamic block base set to 0

2023-07-16 10:01:08.522 [info] 2023-07-16 10:01:08.520908 [I:onnxruntime:, inference_session.cc:1222 Initialize] Initializing session.

2023-07-16 10:01:08.523 [info] 2023-07-16 10:01:08.521190 [I:onnxruntime:, inference_session.cc:1259 Initialize] Adding default CPU execution provider.

2023-07-16 10:01:08.532 [info] 2023-07-16 10:01:08.531129 [I:onnxruntime:, reshape_fusion.cc:42 ApplyImpl] Total fused reshape node count: 0

2023-07-16 10:01:08.537 [info] 2023-07-16 10:01:08.535276 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'rnn/transpose'. It is no longer used by any node.

2023-07-16 10:01:08.537 [info] 2023-07-16 10:01:08.535557 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'Gather_out0'. It is no longer used by any node.
2023-07-16 10:01:08.535771 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'Transpose_out0'. It is no longer used by any node.

2023-07-16 10:01:08.538 [info] 2023-07-16 10:01:08.536922 [I:onnxruntime:, reshape_fusion.cc:42 ApplyImpl] Total fused reshape node count: 0

2023-07-16 10:01:08.617 [info] 2023-07-16 10:01:08.615652 [V:onnxruntime:, session_state.cc:1010 VerifyEachNodeIsAssignedToAnEp] Node placements

2023-07-16 10:01:08.617 [info] 2023-07-16 10:01:08.615923 [V:onnxruntime:, session_state.cc:1013 VerifyEachNodeIsAssignedToAnEp]  All nodes placed on [CPUExecutionProvider]. Number of nodes: 59

2023-07-16 10:01:08.619 [info] 2023-07-16 10:01:08.618049 [V:onnxruntime:, session_state.cc:66 CreateGraphInfo] SaveMLValueNameIndexMapping

2023-07-16 10:01:08.620 [info] 2023-07-16 10:01:08.618869 [V:onnxruntime:, session_state.cc:112 CreateGraphInfo] Done saving OrtValue mappings.

2023-07-16 10:01:08.638 [info] 2023-07-16 10:01:08.622786 [I:onnxruntime:, session_state_utils.cc:199 SaveInitializedTensors] Saving initialized tensors.

2023-07-16 10:01:08.736 [info] 2023-07-16 10:01:08.686598 [I:onnxruntime:, session_state_utils.cc:342 SaveInitializedTensors] Done saving initialized tensors

2023-07-16 10:01:08.737 [info] 2023-07-16 10:01:08.736162 [I:onnxruntime:, inference_session.cc:1488 Initialize] Session successfully initialized.

2023-07-16 10:01:08.743 [info] 2023-07-16 10:01:08.742313 [I:onnxruntime:, inference_session.cc:271 ConstructorCommon] Creating and using per session threadpools since use_per_session_threads_ is true

2023-07-16 10:01:08.744 [info] 2023-07-16 10:01:08.742581 [I:onnxruntime:, inference_session.cc:292 ConstructorCommon] Dynamic block base set to 0

2023-07-16 10:01:08.871 [info] 2023-07-16 10:01:08.869958 [I:onnxruntime:, inference_session.cc:1222 Initialize] Initializing session.

2023-07-16 10:01:08.871 [info] 2023-07-16 10:01:08.870194 [I:onnxruntime:, inference_session.cc:1259 Initialize] Adding default CPU execution provider.

2023-07-16 10:01:08.872 [info] 2023-07-16 10:01:08.871251 [I:onnxruntime:, reshape_fusion.cc:42 ApplyImpl] Total fused reshape node count: 0

2023-07-16 10:01:08.876 [info] 2023-07-16 10:01:08.874761 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'rnn/transpose'. It is no longer used by any node.

2023-07-16 10:01:08.876 [info] 2023-07-16 10:01:08.875020 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'Gather_out0'. It is no longer used by any node.

2023-07-16 10:01:08.876 [info] 2023-07-16 10:01:08.875164 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'Transpose_out0'. It is no longer used by any node.

2023-07-16 10:01:08.877 [info] 2023-07-16 10:01:08.876178 [I:onnxruntime:, reshape_fusion.cc:42 ApplyImpl] Total fused reshape node count: 0

2023-07-16 10:01:08.951 [info] 2023-07-16 10:01:08.933935 [V:onnxruntime:, session_state.cc:1010 VerifyEachNodeIsAssignedToAnEp] Node placements

2023-07-16 10:01:08.951 [info] 2023-07-16 10:01:08.950082 [V:onnxruntime:, session_state.cc:1013 VerifyEachNodeIsAssignedToAnEp]  All nodes placed on [CPUExecutionProvider]. Number of nodes: 59

2023-07-16 10:01:08.952 [info] 2023-07-16 10:01:08.951277 [V:onnxruntime:, session_state.cc:66 CreateGraphInfo] SaveMLValueNameIndexMapping

2023-07-16 10:01:08.953 [info] 2023-07-16 10:01:08.951636 [V:onnxruntime:, session_state.cc:112 CreateGraphInfo] Done saving OrtValue mappings.

2023-07-16 10:01:08.954 [info] 2023-07-16 10:01:08.952701 [I:onnxruntime:, session_state_utils.cc:199 SaveInitializedTensors] Saving initialized tensors.

2023-07-16 10:01:09.125 [info] 2023-07-16 10:01:09.124140 [I:onnxruntime:, session_state_utils.cc:342 SaveInitializedTensors] Done saving initialized tensors

2023-07-16 10:01:09.128 [info] 2023-07-16 10:01:09.126569 [I:onnxruntime:, inference_session.cc:1488 Initialize] Session successfully initialized.

2023-07-16 10:01:09.136 [info] (6404) Created IntelliCode session.
2023-07-16 10:01:09.136 [info] (6404) Created IntelliCode session.
2023-07-16 10:01:09.137 [info] (6404) Initialize deeplearning succeeded
2023-07-16 10:01:09.137 [info] (6404) Initialize deeplearning succeeded
2023-07-16 10:01:09.217 [info] 2023-07-16 10:01:09.216062 [I:onnxruntime:, inference_session.cc:271 ConstructorCommon] Creating and using per session threadpools since use_per_session_threads_ is true

2023-07-16 10:01:09.218 [info] 2023-07-16 10:01:09.216471 [I:onnxruntime:, inference_session.cc:292 ConstructorCommon] Dynamic block base set to 0

2023-07-16 10:01:09.231 [info] 2023-07-16 10:01:09.229785 [I:onnxruntime:, inference_session.cc:1222 Initialize] Initializing session.

2023-07-16 10:01:09.231 [info] 2023-07-16 10:01:09.230000 [I:onnxruntime:, inference_session.cc:1259 Initialize] Adding default CPU execution provider.

2023-07-16 10:01:09.233 [info] 2023-07-16 10:01:09.231227 [I:onnxruntime:, reshape_fusion.cc:42 ApplyImpl] Total fused reshape node count: 0

2023-07-16 10:01:09.242 [info] 2023-07-16 10:01:09.234922 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'rnn/transpose'. It is no longer used by any node.

2023-07-16 10:01:09.248 [info] 2023-07-16 10:01:09.242771 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'Gather_out0'. It is no longer used by any node.

2023-07-16 10:01:09.248 [info] 2023-07-16 10:01:09.247297 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'Transpose_out0'. It is no longer used by any node.

2023-07-16 10:01:09.249 [info] 2023-07-16 10:01:09.248258 [I:onnxruntime:, reshape_fusion.cc:42 ApplyImpl] Total fused reshape node count: 0

2023-07-16 10:01:09.331 [info] 2023-07-16 10:01:09.330226 [V:onnxruntime:, session_state.cc:1010 VerifyEachNodeIsAssignedToAnEp] Node placements

2023-07-16 10:01:09.332 [info] 2023-07-16 10:01:09.330586 [V:onnxruntime:, session_state.cc:1013 VerifyEachNodeIsAssignedToAnEp]  All nodes placed on [CPUExecutionProvider]. Number of nodes: 59

2023-07-16 10:01:09.376 [info] 2023-07-16 10:01:09.332387 [V:onnxruntime:, session_state.cc:66 CreateGraphInfo] SaveMLValueNameIndexMapping

2023-07-16 10:01:09.377 [info] 2023-07-16 10:01:09.375649 [V:onnxruntime:, session_state.cc:112 CreateGraphInfo] Done saving OrtValue mappings.

2023-07-16 10:01:09.378 [info] 2023-07-16 10:01:09.376595 [I:onnxruntime:, session_state_utils.cc:199 SaveInitializedTensors] Saving initialized tensors.

2023-07-16 10:01:09.655 [info] 2023-07-16 10:01:09.654213 [I:onnxruntime:, session_state_utils.cc:342 SaveInitializedTensors] Done saving initialized tensors

2023-07-16 10:01:09.657 [info] 2023-07-16 10:01:09.655551 [I:onnxruntime:, inference_session.cc:1488 Initialize] Session successfully initialized.

2023-07-16 10:01:09.667 [info] (6404) Created IntelliCode session.
2023-07-16 10:01:09.667 [info] (6404) Initialize deeplearning succeeded
2023-07-16 10:01:11.313 [info] 2023-07-16 10:01:11.312142 [I:onnxruntime:, inference_session.cc:271 ConstructorCommon] Creating and using per session threadpools since use_per_session_threads_ is true

2023-07-16 10:01:11.314 [info] 2023-07-16 10:01:11.312452 [I:onnxruntime:, inference_session.cc:292 ConstructorCommon] Dynamic block base set to 0

2023-07-16 10:01:11.341 [info] 2023-07-16 10:01:11.330352 [I:onnxruntime:, inference_session.cc:1222 Initialize] Initializing session.
2023-07-16 10:01:11.331453 [I:onnxruntime:, inference_session.cc:1259 Initialize] Adding default CPU execution provider.
2023-07-16 10:01:11.332276 [I:onnxruntime:, reshape_fusion.cc:42 ApplyImpl] Total fused reshape node count: 0
2023-07-16 10:01:11.334205 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'rnn/transpose'. It is no longer used by any node.
2023-07-16 10:01:11.334362 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'Gather_out0'. It is no longer used by any node.
2023-07-16 10:01:11.334460 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'Transpose_out0'. It is no longer used by any node.
2023-07-16 10:01:11.335145 [I:onnxruntime:, reshape_fusion.cc:42 ApplyImpl] Total fused reshape node count: 0

2023-07-16 10:01:11.353 [info] 2023-07-16 10:01:11.351742 [V:onnxruntime:, session_state.cc:1010 VerifyEachNodeIsAssignedToAnEp] Node placements

2023-07-16 10:01:11.353 [info] 2023-07-16 10:01:11.352009 [V:onnxruntime:, session_state.cc:1013 VerifyEachNodeIsAssignedToAnEp]  All nodes placed on [CPUExecutionProvider]. Number of nodes: 59

2023-07-16 10:01:11.354 [info] 2023-07-16 10:01:11.352946 [V:onnxruntime:, session_state.cc:66 CreateGraphInfo] SaveMLValueNameIndexMapping

2023-07-16 10:01:11.354 [info] 2023-07-16 10:01:11.353416 [V:onnxruntime:, session_state.cc:112 CreateGraphInfo] Done saving OrtValue mappings.

2023-07-16 10:01:11.355 [info] 2023-07-16 10:01:11.354261 [I:onnxruntime:, session_state_utils.cc:199 SaveInitializedTensors] Saving initialized tensors.

2023-07-16 10:01:11.548 [info] 2023-07-16 10:01:11.542779 [I:onnxruntime:, session_state_utils.cc:342 SaveInitializedTensors] Done saving initialized tensors

2023-07-16 10:01:11.551 [info] 2023-07-16 10:01:11.549765 [I:onnxruntime:, inference_session.cc:1488 Initialize] Session successfully initialized.

2023-07-16 10:01:11.572 [info] (6404) Created IntelliCode session.
2023-07-16 10:01:11.573 [info] (6404) Initialize deeplearning succeeded
2023-07-16 10:01:59.063 [info] (6404) [FG] parsing: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\typing.pyi [fs read 5ms] (317ms)
2023-07-16 10:01:59.096 [info] (6404) [FG] binding: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\typing.pyi (28ms)
2023-07-16 10:01:59.141 [info] (6404) [FG] parsing: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\typing_extensions.pyi [fs read 1ms] (40ms)
2023-07-16 10:01:59.162 [info] (6404) [FG] binding: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\typing_extensions.pyi (12ms)
2023-07-16 10:01:59.374 [info] (6404) [FG] parsing: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi [fs read 1ms] (160ms)
2023-07-16 10:01:59.384 [info] (6404) [FG] binding: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi (8ms)
2023-07-16 10:01:59.458 [info] (6404) [FG] parsing: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\types.pyi [fs read 1ms] (69ms)
2023-07-16 10:01:59.490 [info] (6404) [FG] binding: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\types.pyi (36ms)
2023-07-16 10:01:59.577 [info] (6404) [FG] parsing: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\abc.pyi [fs read 1ms] (25ms)
2023-07-16 10:01:59.579 [info] (6404) [FG] binding: c:\Users\USER\.vscode\extensions\ms-python.vscode-pylance-2023.7.20\dist\typeshed-fallback\stdlib\abc.pyi (2ms)
2023-07-16 10:01:59.646 [info] (6404) Background analysis message: getDiagnosticsForRange
2023-07-16 10:01:59.664 [info] (6404) Background analysis message: getDiagnosticsForRange
2023-07-16 10:01:59.668 [info] (6404) Background analysis message: getDiagnosticsForRange
2023-07-16 10:01:59.669 [info] (6404) Background analysis message: getDiagnosticsForRange
2023-07-16 10:01:59.735 [info] (6404) Background analysis message: getDiagnosticsForRange
2023-07-16 10:01:59.736 [info] (6404) Background analysis message: getDiagnosticsForRange
2023-07-16 10:02:07.191 [info] (6404) Background analysis message: getDiagnosticsForRange
2023-07-16 10:02:07.191 [info] (6404) Background analysis message: getDiagnosticsForRange
erictraut commented 1 year ago

Could a pylance team member please transfer to the pyright project? This is a core type checker issue.

erictraut commented 1 year ago

Here's a simplified repro:

from typing import TypeVar, Protocol

T = TypeVar("T")
T_co = TypeVar("T_co", covariant=True)

class FalsePositive(Protocol[T]):
    var: T | None

class Positive(Protocol[T_co]):
    var: T_co | None

And here's an even simpler repro that demonstrates the underlying problem:

from typing import TypeVar

T = TypeVar("T")

def func(x: list[T | None]) -> T | None:
    y: list[object | None] = x # This should generate an error but does not
    return x[0]
erictraut commented 1 year ago

Thanks for the bug report. This will be fixed in the next release of pyright and a future release of pylance.

Why-not-now commented 1 year ago

Thank you, do I close it now?

erictraut commented 1 year ago

Please leave it open. The pylance team will close it once it's in a released version of pylance.