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

Generic subclass of a generic class, using a constrained TypeVar is mishandled #17757

Open
ANogin opened this issue Sep 10, 2024 · 0 comments
Open
Labels
bug mypy got something wrong

Comments

@ANogin
Copy link

ANogin commented Sep 10, 2024

Bug Report

from typing import Generic, TypeVar

T = TypeVar("T")
N = TypeVar("N", int, float)

class C(Generic[T]):
    def __init__(self, c: T):
        self.c = c

class C2(C[N]):
    def __init__(self, c: N):
        super().__init__(c) # Unexpected error

results in an unexpected

error: Argument 1 to "__init__" of "C" has incompatible type "int"; expected "N"  [arg-type]
error: Argument 1 to "__init__" of "C" has incompatible type "float"; expected "N"  [arg-type]

on the last line of the test file.

Your Environment

Confirmed with mypy 1.11.2 in Python 3.11.9, without any flags; does not seem version-specific.

@ANogin ANogin added the bug mypy got something wrong label Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant