FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Replace hard crash with typecheck error when subclass method has the same name as type alias by wesleywright · Pull Request #13015 · python/mypy · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .test  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 2 additions & 1 deletion mypy/checker.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,8 @@ def check_method_override_for_base_with_name(
else:
original_type = NoneType()
else:
assert False, str(base_attr.node)
# Will always fail to typecheck below, since we know the node is a method
original_type = NoneType()
if isinstance(original_node, (FuncDef, OverloadedFuncDef)):
original_class_or_static = original_node.is_class or original_node.is_static
elif isinstance(original_node, Decorator):
Expand Down
28 changes: 28 additions & 0 deletions test-data/unit/check-classes.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7300,3 +7300,31 @@ def identity_wrapper(func: FuncT) -> FuncT:
def foo(self: Any) -> str:
return ""

[case testParentClassWithTypeAliasAndSubclassWithMethod]
from typing import Any, Callable, TypeVar

class Parent:
foo = Callable[..., int]
class bar:
pass
import typing as baz
foobar = TypeVar("foobar")

class Child(Parent):
def foo(self, val: int) -> int: # E: Signature of "foo" incompatible with supertype "Parent"
return val
def bar(self, val: str) -> str: # E: Signature of "bar" incompatible with supertype "Parent"
return val
def baz(self, val: float) -> float: # E: Signature of "baz" incompatible with supertype "Parent"
return val
def foobar(self) -> bool: # E: Signature of "foobar" incompatible with supertype "Parent"
return False

x: Parent.foo = lambda: 5
y: Parent.bar = Parent.bar()
z: Parent.baz.Any = 1
child = Child()
a: int = child.foo(1)
b: str = child.bar("abc")
c: float = child.baz(3.4)
d: bool = child.foobar()

Back | FazBrowse Home | New Git URL