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

Wrong inconsistency detected when overloading a function whose signature involves parametric types #9054

Open
jonathan-laurent opened this issue Sep 22, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jonathan-laurent
Copy link

Pyright 1.1.381 sometimes raises spurious errors when overloading functions whose signature involves parametric types:

# pyright: strict

from typing import overload

class Foo[T]:
    def method(self, x: T) -> int:
        assert False

@overload
def f(x: None) -> int:
    ...

@overload
def f[T](x: Foo[T]) -> int:
    ...

# Error with pyright v1.1.381
# (Accepted by mypy 1.11.1)
def f[T](x: Foo[T] | None) -> int:
    assert False

Here is the detailed error:

error: Overloaded implementation is not consistent with signature of overload 2
    Type "(x: Foo[T@f] | None) -> int" is not assignable to type "(x: Foo[T@f]) -> int"
      Parameter 1: type "Foo[T@f]" is incompatible with type "Foo[T@f] | None"
        Type "Foo[T@f]" is not assignable to type "Foo[T@f] | None"
          "notes.journal.2024-09-22-overload-bug.Foo" is not assignable to "notes.journal.2024-09-22-overload-bug.Foo"
            Type parameter "T@Foo" is contravariant, but "T@f" is not a supertype of "T@f"
          "Foo[T@f]" is not assignable to "None" (reportInconsistentOverload)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant