def create_Callable(args: Iterable[type], rtype: type, class_poly_vars: Set[type] = None) -> Callable: """Initialize and return Callable with given parameters, return types, and polymorphic type variables.""" poly_vars = set(class_poly_vars) if class_poly_vars else set() c = Callable.copy_with(tuple([*args, rtype])) poly_vars.update(_get_poly_vars(c)) c.__polymorphic_tvars__ = frozenset(poly_vars) return c
def _wrap_generic_meta(t: _GenericAlias, args: List[type]) -> TypeResult: if t.__origin__ is tuple: tuple_args = tuple(args) # Handle the special case when t1 or t2 are empty tuples; TODO: investigate this if tuple_args == ((),): tuple_args = () return TypeInfo(Tuple[tuple_args]) elif is_callable(t): c = Callable.copy_with(tuple(args)) c.__polymorphic_tvars__ = getattr(t, '__polymorphic_tvars__', frozenset()) return TypeInfo(c) else: return TypeInfo(t.copy_with(tuple(args)))