I am wanting to be able to add a type annotation that accepts either one or a list of the defined type.
For example, the first func would accept a str or a list of strs, and the second a Path or list of paths.
def foo(names: Listable[str]):
pass
def bar(paths: Listable[Path]):
pass
foo('a') # correct type
foo(['a', 'b']) # correct type
foo([1, 2]) # wrong type
Listable[str] is equivalent to Union[str, list[str]]
Is there a way to achieve this in Python using generics or something similar?