mypy
mypy copied to clipboard
abstract `__init__` signature of `abc.ABC` doesn't get type checked
Bug Report
If an abstract base class has a __init__ that is annotated as @abc.abstractmethod, the signature should be verified for clients implementing the __init__. This does not seem to be the case.
To Reproduce
import abc
class Base(abc.ABC):
@abc.abstractmethod
def __init__(self, a: int):
...
class Client(Base):
def __init__(self, a: str):
...
Expected Behavior
A type error in the child's __init__ because it violates the signature. This works for regular methods, i.e., replacing both __init__ by e.g. foo errors with:
main.py:10: error: Argument 1 of "foo" is incompatible with supertype "Base"; supertype defines the argument type as "int" [override]
main.py:10: note: This violates the Liskov substitution principle
main.py:10: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
Actual Behavior
mypy doesn't detect the type error.
Your Environment
- Mypy version used: 1.4.0
- Mypy command-line flags:
--strict - Mypy configuration options from
mypy.ini(and other config files): (nothing, just using the playground) - Python version used: 3.11