Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect (nested) return type when using TypeVar on classmethod #1437

Closed
skilkis opened this issue Jun 12, 2021 · 3 comments
Closed

Incorrect (nested) return type when using TypeVar on classmethod #1437

skilkis opened this issue Jun 12, 2021 · 3 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@skilkis
Copy link

skilkis commented Jun 12, 2021

Within the last few days, the previous behavior of Pylance has changed. Please see the expected behavior along with the code snippet below. Thanks for the hard work and awesome product 😄

Environment data

  • Language Server version: 2021.6.2-pre.1
  • OS and version: Windows 10.0.19042
  • Python version: CPython 3.7.9 64-bit
  • VS Code version: 1.57.0

Expected behaviour

The return I expect would be

Type[Bar]

Actual behaviour

Instead, the return type is

Type[Type[Bar]]

image

Logs

Expand

[Info  - 11:26:35 AM] Pylance language server 2021.6.2-pre.1 (pyright e3f7cccc) starting
[Info  - 11:26:35 AM] Server root directory: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist
[Info  - 11:26:35 AM] Background analysis(1) root directory: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist
[Info  - 11:26:35 AM] Background analysis(1) started
[Info  - 11:26:35 AM] No configuration file found.
[Info  - 11:26:35 AM] No pyproject.toml file found.
[Info  - 11:26:35 AM] Setting pythonPath for service "issues": "c:\Users\MDRyzenPC\Python\issues\.env\Scripts\python.exe"
[Warn  - 11:26:35 AM] stubPath c:\Users\MDRyzenPC\Python\issues\typings is not a valid directory.
[Info  - 11:26:35 AM] Assuming Python version 3.7
[Info  - 11:26:35 AM] Assuming Python platform Windows
Search paths for c:\Users\MDRyzenPC\Python\issues
  c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stdlib
  c:\Users\MDRyzenPC\Python\issues
  c:\Users\MDRyzenPC\Python\issues\typings
  c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stubs\...
  c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\bundled\stubs
  C:\Python37\python37.zip
  c:\Python37\DLLs
  c:\Python37\Lib
  c:\Python37
  c:\Users\MDRyzenPC\Python\issues\.env
  c:\Users\MDRyzenPC\Python\issues\.env\Lib\site-packages
[Info  - 11:26:36 AM] Searching for source files
[Info  - 11:26:36 AM] Auto-excluding c:\Users\MDRyzenPC\Python\issues\.env
[Info  - 11:26:36 AM] Found 1 source file
[FG] parsing: c:\Users\MDRyzenPC\Python\issues\return_type.py (21ms)
[FG] parsing: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stdlib\builtins.pyi [fs read 4ms] (120ms)
[FG] binding: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stdlib\builtins.pyi (38ms)
[FG] binding: c:\Users\MDRyzenPC\Python\issues\return_type.py (0ms)
Background analysis message: setConfigOptions
Background analysis message: ensurePartialStubPackages
Background analysis message: setTrackedFiles
Background analysis message: markAllFilesDirty
Background analysis message: setFileOpened
Background analysis message: analyze
[BG(1)] analyzing: c:\Users\MDRyzenPC\Python\issues\return_type.py ...
[BG(1)]   parsing: c:\Users\MDRyzenPC\Python\issues\return_type.py (20ms)
[BG(1)]   parsing: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stdlib\builtins.pyi [fs read 3ms] (100ms)
[Info  - 11:26:36 AM] Indexer background runner(2) root directory: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist
[Info  - 11:26:36 AM] Indexing(2) started
[BG(1)]   binding: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stdlib\builtins.pyi (31ms)
[BG(1)]   binding: c:\Users\MDRyzenPC\Python\issues\return_type.py (0ms)
[BG(1)]   checking: c:\Users\MDRyzenPC\Python\issues\return_type.py ...
[BG(1)]     parsing: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stdlib\typing.pyi [fs read 2ms] (24ms)
[BG(1)]     binding: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stdlib\typing.pyi (11ms)
[BG(1)]     parsing: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi [fs read 0ms] (5ms)
[BG(1)]     binding: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi (1ms)
[BG(1)]     parsing: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stdlib\typing_extensions.pyi [fs read 0ms] (2ms)
[BG(1)]     binding: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stdlib\typing_extensions.pyi (1ms)
[BG(1)]   checking: c:\Users\MDRyzenPC\Python\issues\return_type.py (76ms)
[BG(1)] analyzing: c:\Users\MDRyzenPC\Python\issues\return_type.py (229ms)
Background analysis message: getSemanticTokens full
[IDX(2)] index libraries c:\Users\MDRyzenPC\Python\issues ...
[IDX(2)]   read stdlib indices (102ms)
[BG(1)] getSemanticTokens full at c:\Users\MDRyzenPC\Python\issues\return_type.py (5ms)
Background analysis message: getSemanticTokens range
[BG(1)] getSemanticTokens range 0:0 - 16:0 at c:\Users\MDRyzenPC\Python\issues\return_type.py (2ms)
Background analysis message: resumeAnalysis
[BG(1)] indexing: c:\Users\MDRyzenPC\Python\issues\return_type.py [found 4] (0ms)
Indexing Done: c:\Users\MDRyzenPC\Python\issues\return_type.py
[IDX(2)]   scan packages [found 14 modules over 1 exec env] (249ms)
[IDX(2)]   index execution environment c:\Users\MDRyzenPC\Python\issues ...
[IDX(2)]     parsing: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stubs\pkg_resources\pkg_resources\__init__.pyi [fs read 2ms] (57ms)
[IDX(2)]     parsing: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stdlib\builtins.pyi [fs read 1ms] (50ms)
[IDX(2)]     binding: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stdlib\builtins.pyi (11ms)
[IDX(2)]     binding: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stubs\pkg_resources\pkg_resources\__init__.pyi (1ms)
[IDX(2)]     indexing: c:\Users\MDRyzenPC\.vscode\extensions\ms-python.vscode-pylance-2021.6.2-pre.1\dist\typeshed-fallback\stubs\pkg_resources\pkg_resources\__init__.pyi [found 70] (1ms)
[IDX(2)]     parsing: c:\Python37\Lib\xml\__init__.py [fs read 1ms] (6ms)
[IDX(2)]     binding: c:\Python37\Lib\xml\__init__.py (0ms)
[IDX(2)]     indexing: c:\Python37\Lib\xml\__init__.py [found 0] (0ms)
[IDX(2)]     parsing: c:\Users\MDRyzenPC\Python\issues\.env\Lib\site-packages\setuptools\__init__.py [fs read 0ms] (12ms)
[IDX(2)]     binding: c:\Users\MDRyzenPC\Python\issues\.env\Lib\site-packages\setuptools\__init__.py (2ms)
[IDX(2)]     indexing: c:\Users\MDRyzenPC\Python\issues\.env\Lib\site-packages\setuptools\__init__.py ...
[IDX(2)]       parsing: c:\Users\MDRyzenPC\Python\issues\.env\Lib\site-packages\setuptools\_deprecation_warning.py [fs read 0ms] (0ms)
[IDX(2)]       binding: c:\Users\MDRyzenPC\Python\issues\.env\Lib\site-packages\setuptools\_deprecation_warning.py (0ms)
[IDX(2)]       parsing: c:\Users\MDRyzenPC\Python\issues\.env\Lib\site-packages\setuptools\extension.py [fs read 0ms] (1ms)
[IDX(2)]       binding: c:\Users\MDRyzenPC\Python\issues\.env\Lib\site-packages\setuptools\extension.py (1ms)
[IDX(2)]       parsing: c:\Users\MDRyzenPC\Python\issues\.env\Lib\site-packages\setuptools\dist.py [fs read 0ms] (23ms)
[IDX(2)]       binding: c:\Users\MDRyzenPC\Python\issues\.env\Lib\site-packages\setuptools\dist.py (0ms)
[IDX(2)]       parsing: c:\Users\MDRyzenPC\Python\issues\.env\Lib\site-packages\setuptools\depends.py [fs read 0ms] (1ms)
[IDX(2)]       binding: c:\Users\MDRyzenPC\Python\issues\.env\Lib\site-packages\setuptools\depends.py (1ms)
[IDX(2)]     indexing: c:\Users\MDRyzenPC\Python\issues\.env\Lib\site-packages\setuptools\__init__.py [found 8] (29ms)
[IDX(2)]   index execution environment c:\Users\MDRyzenPC\Python\issues [found 7933 in 407 files] (173ms)
[IDX(2)] index libraries c:\Users\MDRyzenPC\Python\issues [found 7933 in 1 exec envs] (525ms)
[Info  - 11:26:36 AM] Indexer done(2). indexed 407 files

Code Snippet / Additional information

from typing import Type, TypeVar

T = TypeVar("T", bound="Foo")


class Foo:
    @classmethod
    def get(cls: Type[T]) -> Type[T]:
        return cls


class Bar(Foo):
    pass


bar_type: Type[Bar] = Bar.get()
@erictraut
Copy link
Contributor

Thanks for the bug report. This was a latent bug that was uncovered by a recent change. It will be fixed in the next release.

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Jun 13, 2021
@skilkis
Copy link
Author

skilkis commented Jun 14, 2021

Awesome, thanks for the quick fix!

@bschnurr
Copy link
Member

This issue has been fixed in version 2021.6.2, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202162-16-june-2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants