Consider the following two cases, which only should yield a single type_var T.
# Python < 3.11
from typing_extensions import Unpack, TypeVarTuple, _collect_type_vars, Tuple, TypeVar, TypedDict, Generic
Ts = TypeVarTuple("Ts")
T= TypeVar("T")
class Movie(Generic[T], TypedDict):;
genre : T
print(_collect_type_vars([Unpack[Movie[T]]]))
# (typing_extensions.Unpack[typing_extensions.Movie[~T]], ~T)
print(_collect_type_vars([Unpack[Tuple[T]]]))
# (typing_extensions.Unpack[typing.Tuple[~T]], ~T)
The problem is that the second condition isinstance(Unpack_instance, TypeVar) is True, which appends the unpack variable itself which makes no sense.
typing_extensions monkey patches this function in the typing module