Consider the following function
import typing
def make_list(el : typing.Any):
return [el, el]
How do I hint that it returns
typing.List[type(el)]
That's what TypeVar
is for:
from typing import TypeVar, List
T = TypeVar('T')
def make_list(el: T) -> List[T]:
return [el, el]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With