Reputation: 925
Assuming T = TypeVar('T')
Optional[T] hint is interpreted to Union[T, None].
Is there any equivalent for Sequence hint, so that it will be interpreted to Union[T, Sequence[T]]?
Upvotes: 0
Views: 163
Reputation: 522034
You can define such a type like this:
T = TypeVar('T')
MaybeSequence = Union[T, Sequence[T]]
foo: MaybeSequence[str]
Upvotes: 1