Skip to content

Instantly share code, notes, and snippets.

@nbraud nbraud/results
Created Oct 21, 2018

Embed
What would you like to do?
$ mypy test.bad.py
test.bad.py:22: error: "V2" has no attribute "method"
$ mypy /tmp/test.good.py
[no errors returned]
import typing
VectorLike = typing.Union[
'V2',
typing.Tuple[int, int],
]
class V2:
def __init__(self, x: int, y: int) -> None:
pass
def __add__(self, other: VectorLike) -> V2:
return self
class V(V2):
def method(self) -> typing.NoReturn:
raise NotImplementedError
x = V(1, 0) + (0, 1)
x.method()
from numbers import Real
import typing
VectorLike = typing.Union[
'V2',
typing.Tuple[int, int],
]
class V2:
def __init__(self, x: int, y: int) -> None:
pass
T = typing.TypeVar('T', bound=V2)
def __add__(self: T, other: VectorLike) -> T:
return self
class V(V2):
def method(self) -> typing.NoReturn:
raise NotImplementedError
x = V(1, 0) + (0, 1)
x.method()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.