I want to use a type checker that helps me writing good code and I think mypy does what I want. But I do not get how to write the following code.
import typing as tau
Offset = tau.NewType('Offset', tau.Tuple[int, int])
def f(x: int, y: int) -> Offset:
return x, y
important_for_me = Offset != tau.Tuple[int, int]
assert important_for_me
For a framework I am writing it is important to not just assign an identifier to a type, but I still want the typechecker to know how to help me (so not just assign TypeVar and lose information).
typing.NewType works perfectly fine, but mypy gives me an error at line 7:
Incompatible return value type (got "Tuple[int, int]", expected "Offset")
Is there a way how to write it exactly like I did but in a way that the typechecker understands it?
