Skip to content

Instantly share code, notes, and snippets.

@masahitojp
Created July 12, 2019 07:48
Show Gist options
  • Save masahitojp/b550c754aa8d402e7690c54e8f7b4dea to your computer and use it in GitHub Desktop.
Save masahitojp/b550c754aa8d402e7690c54e8f7b4dea to your computer and use it in GitHub Desktop.
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