Skip to content

Fix crash on invalid callable property override #17352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ def erase_override(t: Type) -> Type:
):
arg_type_in_super = original.arg_types[i]

if isinstance(node, FuncDef):
if isinstance(node, FuncDef) and not node.is_property:
context: Context = node.arguments[i + len(override.bound_args)]
else:
context = node
Expand Down
22 changes: 22 additions & 0 deletions test-data/unit/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -3302,3 +3302,25 @@ class C: # Note: Generic[T] missing

def nope(self, x: T) -> None:
self.x = x # E: Incompatible types in assignment (expression has type "T@nope", variable has type "T@bad_idea")

[case testNoCrashOnBadCallablePropertyOverride]
from typing import Callable, Union

class C: ...
class D: ...

A = Callable[[C], None]
B = Callable[[D], None]

class Foo:
@property
def method(self) -> Callable[[int, Union[A, B]], None]:
...

class Bar(Foo):
@property
def method(self) -> Callable[[int, A], None]: # E: Argument 2 of "method" is incompatible with supertype "Foo"; supertype defines the argument type as "Union[Callable[[C], None], Callable[[D], None]]" \
# N: This violates the Liskov substitution principle \
# N: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
...
[builtins fixtures/property.pyi]
Loading