Last active
January 4, 2023 13:11
-
-
Save giuliano-macedo/7d2194c9fcdd8f8071ccbd173461e037 to your computer and use it in GitHub Desktop.
Example for SO question: https://stackoverflow.com/questions/74914319/how-to-type-only-the-first-positional-parameter-of-a-protocol-method-and-let-the/75002538#75002538
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
T = TypeVar("T") | |
class MyProtocol(Protocol[T]): | |
def my_method(self, first_param: int, args: T) -> int: | |
... | |
@dataclass | |
class Imp1Args: | |
x: float | |
y: float | |
class Imp1(MyProtocol[Imp1Args]): | |
def my_method(self, first_param: int, args: Imp1Args) -> int: | |
return int(args.x + args.y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment