MCPcopy Index your code
hub / github.com/python/mypy / tuple_fallback

Function tuple_fallback

mypy/typeops.py:105–131  ·  view source on GitHub ↗

Return fallback type for a tuple.

(typ: TupleType)

Source from the content-addressed store, hash-verified

103
104
105def tuple_fallback(typ: TupleType) -> Instance:
106 """Return fallback type for a tuple."""
107 info = typ.partial_fallback.type
108 if info.fullname != "builtins.tuple":
109 return typ.partial_fallback
110 items = []
111 for item in typ.items:
112 if isinstance(item, UnpackType):
113 unpacked_type = get_proper_type(item.type)
114 if isinstance(unpacked_type, TypeVarTupleType):
115 unpacked_type = get_proper_type(unpacked_type.upper_bound)
116 if (
117 isinstance(unpacked_type, Instance)
118 and unpacked_type.type.fullname == "builtins.tuple"
119 ):
120 items.append(unpacked_type.args[0])
121 else:
122 raise NotImplementedError
123 else:
124 items.append(item)
125 return Instance(
126 info,
127 # Note: flattening recursive unions is dangerous, since it can fool recursive
128 # types optimization in subtypes.py and go into infinite recursion.
129 [make_simplified_union(items, handle_recursive=False)],
130 extra_attrs=typ.partial_fallback.extra_attrs,
131 )
132
133
134def get_self_type(func: CallableType, def_info: TypeInfo) -> Type | None:

Calls 5

get_proper_typeFunction · 0.90
InstanceClass · 0.90
isinstanceFunction · 0.85
make_simplified_unionFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…