-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
Bug Report
mypy isn't accepting Mapping[str, object] as TypedDict parent.
test.py:18: error: Argument 1 of "do_handle" is incompatible with supertype "IHandle"; supertype defines the argument type as "Mapping[str, object]"
test.py:18: note: This violates the Liskov substitution principle
test.py:18: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides(A clear and concise description of what the bug is.)
To Reproduce
from abc import ABC, abstractmethod
from typing import Mapping, TypedDict
PayloadType = Mapping[str, object]
class ArgumentType(TypedDict):
name: str
class ReturnType(TypedDict):
result: bool
class IHandle(ABC):
@abstractmethod
def do_handle(self, name: PayloadType) -> PayloadType:
...
class Handler(IHandle):
def do_handle(self, name: ArgumentType) -> ReturnType:
return {
'result': True,
}
handler = Handler()
name: ArgumentType = {'name': 'example'}
handler.do_handle(name)Expected Behavior
ArgumentType and ReturnType are both subtypes of TypedDict and TypedDict is a subtype of Mapping[str, object] therefore its not a violation.
Actual Behavior
ArguementType violates the liskov subsition principle whereas ReturnType doesn't?
Your Environment
- Mypy version used: mypy 0.960 (compiled: yes)
- Mypy command-line flags: mypy
- Mypy configuration options from
mypy.ini(and other config files): NA. - Python version used: Python 3.9.0
- Operating system and version: Linux