Created
March 15, 2022 13:00
-
-
Save bryanmylee/af4138b8bad14f755613ef8e7c52df41 to your computer and use it in GitHub Desktop.
Add type hints to a Python factory method
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 typing import Type, TypeVar | |
T = TypeVar('T', bound='TrivialClass') | |
class TrivialClass: | |
# ... | |
@classmethod | |
def from_int(cls: Type[T], int_arg: int) -> T: | |
# ... | |
return cls(...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment