-
Notifications
You must be signed in to change notification settings - Fork 290
Closed
Labels
topic: featureDiscussions about new features for Python's type annotationsDiscussions about new features for Python's type annotations
Description
Consider version 1 of my package, which defines
T = TypeVar('T', int, float)
MyType = Union[T, List[T]]
# in the user's code
U = TypeVar('U', int, float)
def myfunc(MyType[U], U): ...In version 2, I decide to drop support for passing List[T]. However, this causes an error on the downstream type definitions
T = TypeVar('T', int, float)
MyType = Union[T] # or Generic[T], or T - all fail
# downstream code doesn't change - I want the freedom to change `MyType` again in future
U = TypeVar('U', int, float)
def myfunc(MyType[U], U): ... # fails due to missing __getitem__Is there a way to write this? Does implementing TypeVar.__getitem__ seem reasonable? Or should we introduce Identity[T], which boxes a typevar into a generic?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
topic: featureDiscussions about new features for Python's type annotationsDiscussions about new features for Python's type annotations