Last active
March 12, 2019 16:10
-
-
Save enomado/5e07f194d1b1ab43dfb55b0f8944664f to your computer and use it in GitHub Desktop.
mypy generic with extends Interface
This file contains 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
# generic with extends Interface | |
class PointableProtocol(Protocol): | |
x: Any | |
y: Any | |
def __init__(self, x: Any, y: Any) -> None: | |
pass | |
T = TypeVar("T", bound=PointableProtocol) | |
def normalize_point_order(p1: T, p2: T) -> Tuple[T, T]: | |
runtime_type = p1.__class__ | |
res1 = runtime_type(int(min(p1.x, p2.x)), int(min(p1.y, p2.y))) | |
res2 = runtime_type( | |
int(max(p1.x, p2.x)), int(max(p1.y, p2.y)) | |
) | |
return res1, res2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment