Skip to content

Instantly share code, notes, and snippets.

@piotr-piatkowski
Created October 13, 2023 11:27
Show Gist options
  • Save piotr-piatkowski/1f5a99fd0f167dc695cf7b540de849fd to your computer and use it in GitHub Desktop.
Save piotr-piatkowski/1f5a99fd0f167dc695cf7b540de849fd to your computer and use it in GitHub Desktop.
$ mypy t.py
t.py:16: error: Argument 1 of "foo" is incompatible with supertype "BaseTest"; supertype defines the argument type as "TBase" [override]
t.py:16: note: This violates the Liskov substitution principle
t.py:16: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
Found 1 error in 1 file (checked 1 source file)
#!/usr/bin/env python3
from pydantic import BaseModel
class TBase:
pass
class TDerived(TBase):
pass
class BaseTest(BaseModel):
def foo(self, v: TBase) -> TBase:
return v
class DerivedTest(BaseTest):
def foo(self, v: TDerived) -> TDerived:
return v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment