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

Detect inconsistent overload with TypeVar #1778

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

Detect inconsistent overload with TypeVar #1778

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

Environment data

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

Code Snippet

from typing import Literal, TypeVar, overload

T = TypeVar("T", int, str)

@overload
def func(option: Literal["a"], var: str) -> str:
    ...

@overload
def func(option: Literal["b"], var: int) -> str:  # Return type must be: int
    ...

def func(option: Literal["a", "b"], var: T) -> T:
    pass

Expected behaviour

Overload 2 is inconsistent with function signature.

Mypy

error: Overloaded function implementation cannot satisfy signature 2 due to inconsistencies in how they use type variables

Actual behaviour

no error

Additional information

After changing the return type of oveload 2 to list, pylance will emit an error:

Overloaded function implementation is not consistent with signature of overload 2
  Function return type "list[Unknown]" is incompatible with type "T@func"
    Type "list[Unknown]" cannot be assigned to type "int* | str*"
      "list[Unknown]" is incompatible with "int*"
      "list[Unknown]" is incompatible with "str*"
@github-actions github-actions bot added the triage label Sep 7, 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 triage labels Sep 8, 2021
@jakebailey
Copy link
Member

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

3 participants