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

False-positive inconsistent overload with TypeVar and Union #1808

Closed
cdce8p opened this issue Sep 12, 2021 · 3 comments
Closed

False-positive inconsistent overload with TypeVar and Union #1808

cdce8p opened this issue Sep 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

@cdce8p
Copy link

cdce8p commented Sep 12, 2021

Environment data

  • Language Server version: 2021.9.1
  • OS and version: darwin x64
  • Python version: 3.10.0rc2
  • python.analysis.indexing: true
  • python.analysis.typeCheckingMode: basic

Expected behaviour

no error

Actual behaviour

Overloaded function implementation is not consistent with signature of overload 1
  Type "(var: T@func | int) -> (T@func | int)" cannot be assigned to type "(var: T@func) -> T@func"
    Parameter 1: type "T@func" cannot be assigned to type "T@func | int"

Logs

--

Code Snippet / Additional information

from typing import TypeVar, overload

class X: ...
class Y: ...

T = TypeVar("T", bound=type[X])

@overload
def func(var: T) -> T:
    ...

@overload
def func(var: int) -> int:
    ...

def func(var: T | int) -> T | int:  # error
    ...


# The type is inferred correctly
reveal_type(func(X))  # Type of "func(X)" is "Type[X]"

Mypy output

Revealed type is "def () -> test3.X"

An error also occurs when changing the TypeVar definition to

T = TypeVar("T", X, Y)

Interestingly though, this seems to be fine:

T = TypeVar("T", bound=X)
@judej
Copy link
Contributor

judej commented Sep 13, 2021

Thanks for the report

@github-actions github-actions bot removed the triage label Sep 13, 2021
@erictraut
Copy link
Contributor

Thanks for the bug report. This 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 needs investigation Could be an issue - needs investigation labels Sep 16, 2021
@jakebailey
Copy link
Member

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

4 participants