Return fallback type for a tuple.
(typ: TupleType)
| 103 | |
| 104 | |
| 105 | def 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 | |
| 134 | def get_self_type(func: CallableType, def_info: TypeInfo) -> Type | None: |
no test coverage detected
searching dependent graphs…