Created
July 12, 2019 07:48
-
-
Save masahitojp/b550c754aa8d402e7690c54e8f7b4dea to your computer and use it in GitHub Desktop.
check generics for mypy
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
from typing import TypeVar, Generic | |
T = TypeVar('T', bound='Shape') | |
class Stack(Generic[T]): | |
def __init__(self) -> None: | |
# Create an empty list with items of type a T | |
print(__annotations__) # {} | |
self.items: List[T] = [] | |
stack:Stack[int] = Stack[int]() | |
print(__annotations__) # {'stack': __main__.Stack[int]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment