Returns the Instance fallback for this type if one exists or None.
(typ: ProperType)
| 58 | |
| 59 | |
| 60 | def get_instance_fallback(typ: ProperType) -> list[Instance]: |
| 61 | """Returns the Instance fallback for this type if one exists or None.""" |
| 62 | if isinstance(typ, Instance): |
| 63 | return [typ] |
| 64 | elif isinstance(typ, TupleType): |
| 65 | return [tuple_fallback(typ)] |
| 66 | elif isinstance(typ, TypedDictType): |
| 67 | return [typ.fallback] |
| 68 | elif isinstance(typ, FunctionLike): |
| 69 | return [typ.fallback] |
| 70 | elif isinstance(typ, LiteralType): |
| 71 | return [typ.fallback] |
| 72 | elif isinstance(typ, TypeVarType): |
| 73 | if typ.values: |
| 74 | res = [] |
| 75 | for t in typ.values: |
| 76 | res.extend(get_instance_fallback(get_proper_type(t))) |
| 77 | return res |
| 78 | return get_instance_fallback(get_proper_type(typ.upper_bound)) |
| 79 | elif isinstance(typ, UnionType): |
| 80 | res = [] |
| 81 | for t in typ.items: |
| 82 | res.extend(get_instance_fallback(get_proper_type(t))) |
| 83 | return res |
| 84 | return [] |
| 85 | |
| 86 | |
| 87 | def find_node(name: str, info: TypeInfo) -> Var | FuncBase | None: |
no test coverage detected
searching dependent graphs…