bpo-42195: Override _CallableGenericAlias's __getitem__ by Fidget-Spinner · Pull Request #23915 · python/cpython
def __getitem__(self, item): # Called during TypeVar substitution, returns the custom subclass # rather than the default types.GenericAlias object. ga = super().__getitem__(item) args = ga.__args__ t_result = args[-1] t_args = args[:-1] args = (t_args, t_result) return _CallableGenericAlias(Callable, args)
def _type_repr(obj): """Return the repr() of an object, special-casing types (internal helper).