Skip to content

Instantly share code, notes, and snippets.



Created Jul 12, 2019
What would you like to do?
check generics for mypy
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
You can’t perform that action at this time.