File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -2367,10 +2367,11 @@ def erase_override(t: Type) -> Type:
23672367 else :
23682368 continue
23692369 if not is_subtype (original_arg_type , erase_override (override_arg_type )):
2370+ context : Context = node
23702371 if isinstance (node , FuncDef ) and not node .is_property :
2371- context : Context = node .arguments [i + len (override .bound_args )]
2372- else :
2373- context = node
2372+ arg_node = node .arguments [i + len (override .bound_args )]
2373+ if arg_node . line != - 1 :
2374+ context = arg_node
23742375 self .msg .argument_incompatible_with_supertype (
23752376 i + 1 ,
23762377 name ,
Original file line number Diff line number Diff line change @@ -2523,3 +2523,18 @@ reveal_type(replaced_2) # N: Revealed type is "__main__.Gen[builtins.int]"
25232523Gen(2).__replace__(x="not an int") # E: Argument "x" to "__replace__" of "Gen" has incompatible type "str"; expected "int"
25242524
25252525[builtins fixtures/tuple.pyi]
2526+
2527+ [case testDunderReplaceCovariantOverride]
2528+ # flags: --python-version 3.13
2529+ from dataclasses import dataclass
2530+
2531+ @dataclass
2532+ class Base:
2533+ a: object
2534+
2535+ @dataclass
2536+ class Child(Base): # E: Argument 1 of "__replace__" is incompatible with supertype "Base"; supertype defines the argument type as "object" \
2537+ # N: This violates the Liskov substitution principle \
2538+ # N: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
2539+ a: int
2540+ [builtins fixtures/tuple.pyi]
You can’t perform that action at this time.
0 commit comments