5

Mypy seems to have trouble understanding a property is not a callable method of a class:

from abc import abstractmethod
from typing import Type


class A:
    pass


class B:
    @abstractmethod
    @property
    @classmethod
    def other_type(cls) -> Type[A]:
        pass

    @classmethod
    def __init_subclass__(cls, **kwargs):
        assert issubclass(cls.other_type, A)

Running mypy on the above example results in the following error:

error: Argument 1 to "issubclass" has incompatible type "Callable[[], Type[A]]"; expected "type"  [arg-type]

How can I enforce the correct type, without # type: ignore[arg-type]? I'm using mypy version 0.782 and python 3.7

(Note: I'm running mypy with the --check-untyped-defs flag, so mypy should be scanning the __init_subclass__ method).

Wombatz
  • 4,958
  • 1
  • 26
  • 35
Dori
  • 1,035
  • 1
  • 12
  • 22
  • I don't see an error running this in the [mypy playground](https://mypy-play.net/?mypy=0.780&python=3.7) – joel Apr 13 '22 at 11:55
  • indeed i wouldn't expect to see one as `__init_subclass__` is untyped and my memory is that mypy doesn't check untyped methods – joel Apr 13 '22 at 11:57
  • @joel I updated the question (I use the `--check-untyped-defs` flag) – Dori Apr 13 '22 at 12:10
  • I'm not sure if what you're trying is even valid before Python 3.9, but regardless there is an issue open on mypy about this https://github.com/python/mypy/issues/11619 – bgfvdu3w Apr 29 '22 at 20:15

0 Answers0