-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -828,6 +828,48 @@ main: In class "D": | |
main, line 6: disjointclass constraint of class B disallows A as a base class | ||
|
||
|
||
-- Operator methods | ||
-- ---------------- | ||
|
||
|
||
[case testOperatorMethodOverrideIntroducingOverloading] | ||
from typing import overload | ||
class A: | ||
def __add__(self, x: int) -> int: pass | ||
class B(A): | ||
@overload # E: Signature of "__add__" incompatible with supertype "A" | ||
def __add__(self, x: int) -> int: pass | ||
@overload | ||
def __add__(self, x: str) -> str: pass | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
elazarg
Contributor
|
||
[out] | ||
main: In class "B": | ||
|
||
[case testOperatorMethodOverrideWideningArgumentType] | ||
from typing import overload | ||
class A: | ||
def __add__(self, x: int) -> int: pass | ||
class B(A): | ||
def __add__(self, x: object) -> int: pass # E: Argument 1 of "__add__" incompatible with supertype "A" | ||
[out] | ||
main: In class "B": | ||
|
||
[case testOperatorMethodOverrideNarrowingReturnType] | ||
from typing import overload | ||
class A: | ||
def __add__(self, x: int) -> 'A': pass | ||
class B(A): | ||
def __add__(self, x: int) -> 'B': pass | ||
[out] | ||
|
||
[case testOperatorMethodOverrideWithDynamicallyTyped] | ||
from typing import overload | ||
class A: | ||
def __add__(self, x: int) -> 'A': pass | ||
class B(A): | ||
def __add__(self, x): pass | ||
[out] | ||
|
||
|
||
-- Special cases | ||
-- ------------- | ||
|
||
|
In what sense is this code unsafe? Is there an example of otherwise-unrejected code that leads to runtime error using this operation?