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

Type unknown when instantiating type of TypeVar or Union #1422

Closed
cdce8p opened this issue Jun 10, 2021 · 3 comments
Closed

Type unknown when instantiating type of TypeVar or Union #1422

cdce8p opened this issue Jun 10, 2021 · 3 comments
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version type checking

Comments

@cdce8p
Copy link

cdce8p commented Jun 10, 2021

Environment data

  • Language Server version: 2021.6.1
  • OS and version: darwin x64
  • Python version: 3.10.0b2
  • python.analysis.indexing: undefined
  • python.analysis.typeCheckingMode: basic

Code Snippet

from typing import TypeVar

class A: ...
class B: ...

T = TypeVar("T", A, B)

def func(cls: type[T]) -> T:
    instance1 = cls()
    reveal_type(instance1)  # Unknown
    return instance1


def func2(cls: type[A | B]) -> A | B:
    instance2 = cls()
    reveal_type(instance2)  # Unknown
    return instance2

Expected behaviour

instance1: T
instance2: A | B

The mypy output

test.py:10: note: Revealed type is "test.A"
test.py:10: note: Revealed type is "test.B"
test.py:16: note: Revealed type is "Union[test.A, test.B]"

Actual behaviour

Both, instance1 and instance2, are unknown.

Logs

--
@erictraut
Copy link
Contributor

Thanks for the feature request. The type checker currently works with type[A] | type[B], but I agree that it should also work with type[A | B] and type[T].

@erictraut
Copy link
Contributor

This will be addressed in the next release.

@erictraut erictraut added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Jun 13, 2021
@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
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version type checking
Projects
None yet
Development

No branches or pull requests

5 participants