mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Incompatible types when calling generinc `__init__` from generic `@classmethod`

Open bjoernpollex opened this issue 4 months ago • 1 comments

Bug Report

When calling a generic __init__ from a generic @classmethod on a class that is itself not generic, mypy reports incompatible types.

To Reproduce

from typing import TypeVar

T = TypeVar("T")


class Foo:
    @classmethod
    def make_foo(cls, arg: T) -> None:
        cls(arg)

    def __init__(self, arg: T) -> None:
        pass

Expected Behavior

mypy reports no errors.

Actual Behavior

error: Argument 1 to "Foo" has incompatible type "T@make_foo"; expected "T@__init__"

Your Environment

  • Mypy version used: mypy 1.11.2 (compiled: yes)
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: Python 3.11.7

bjoernpollex avatar Oct 14 '24 09:10 bjoernpollex