from typing import TypeVar, Any, Union V = TypeVar("V", str, bytes) def check_v(x: Union[V, list[V]]) -> V: raise NotImplementedError() def foo(a: list[Any]) -> None: check_v(a)