Created
February 9, 2022 23:25
-
-
Save mypy-play/ae857a70e22acdec0111e8e01aa60aa3 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
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
from abc import abstractmethod | |
from typing import TypeVar, Generic, Protocol | |
class P1(Protocol): | |
def predict(self): ... | |
class P2(Protocol, P1): | |
def predict_proba(self): ... | |
T1 = TypeVar("T1", bound=P1) | |
T2 = TypeVar("T2", bound=P2) | |
class Spaghetti(Generic[T1]): ... | |
class A(Spaghetti[T1]): | |
@abstractmethod | |
def _do_f(self): ... | |
def do_f(self): | |
# Some validation and do some class things | |
self._do_f() | |
# Do some more things for the class | |
class A1(A[T1]): ... | |
class A2(A[T2]): | |
@abstractmethod | |
def _do_h(self): ... | |
def do_h(self): | |
self._do_h() | |
class B(A[T1]): | |
def _do_f(self): ... | |
class RegressorB(B[T1], A1[T1]): ... | |
class B2(B[T2], A2[T2]): | |
def _do_h(self): ... | |
class X: | |
def f(self): | |
pass | |
class Y: | |
def f(self): | |
pass | |
def h(self): | |
pass | |
B2[Y]() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment