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

mypy tries to infer the type parameters of a generic class even if they are explicitly given #17916

Open
v-- opened this issue Oct 10, 2024 · 0 comments
Labels
bug mypy got something wrong

Comments

@v--
Copy link

v-- commented Oct 10, 2024

Bug Report

mypy tries to infer the type parameters of a generic class even if they are explicitly given.

To Reproduce

from typing import overload


class Frobnicator[T]:  # Using a TypeVar gives identical results
    @overload
    def __init__(self, param: T) -> None: ...
    @overload  # Removing `param` in this case gives identical results
    def __init__(self: 'Frobnicator[None]', param: None = None) -> None: ... 
    def __init__(self, param: T | None = None) -> None:
        ...

Expected Behavior

I expect the following to produce a "missing argument" error (like Pyright 1.1.384 does).

f = Frobnicator[int]()

Actual Behavior

reveal_type(f) shows Frobnicator[None]

Your Environment

The behavior is identical for mypy v1.11.1, v1.11.2 and the master branch, with both Python 3.12 and 3.13. I tried it on my local Arch + pyenv based setup and, using TypeVar, in https://mypy-play.net

@v-- v-- added the bug mypy got something wrong label Oct 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