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

Inconsistent function overload error with type and TypeVar #1407

Closed
cdce8p opened this issue Jun 7, 2021 · 2 comments
Closed

Inconsistent function overload error with type and TypeVar #1407

cdce8p opened this issue Jun 7, 2021 · 2 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

@cdce8p
Copy link

cdce8p commented Jun 7, 2021

Environment data

  • Language Server version: 2021.6.0
  • OS and version: darwin x64
  • Python version (and distribution if applicable, e.g. Anaconda): 3.10.0b2
  • python.analysis.indexing: undefined
  • python.analysis.typeCheckingMode: basic

Code snippet

from typing import overload, TypeVar

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

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

@overload
def func(cls: type[A], var: int) -> A: ...

@overload
def func(cls: type[B], var: str) -> B: ...

def func(cls: type[T], var: int | str) -> T:   # error here
    reveal_type(cls)
    a = cls()
    reveal_type(a)
    return a

Expected behaviour

No error. This does seem to work with mypy. Am I missing something obvious?

test.py:15: note: Revealed type is "Type[test.A*]"
test.py:15: note: Revealed type is "Type[test.B*]"
test.py:17: note: Revealed type is "test.A"
test.py:17: note: Revealed type is "test.B"

Actual behaviour

Overloaded function implementation is not consistent with signature of overload 1
  Type "(cls: Type[T@func], var: int | str) -> T@func" cannot be assigned to type "(cls: Type[A], var: int) -> A"
    Parameter 1: type "Type[A]" cannot be assigned to type "Type[T@func]"
      Type "Type[A]" cannot be assigned to type "Type[T@func]"
        Type "Type[A]" cannot be assigned to type "A* | B*"
          "Type[type]" is incompatible with "Type[A]*"
          "Type[type]" is incompatible with "Type[B]*"PylancereportGeneralTypeIssues

Logs

--
@erictraut
Copy link
Contributor

Thanks for the bug report. This will be fixed 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 8, 2021
@jakebailey
Copy link
Member

This issue has been fixed in version 2021.6.1, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202161-9-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