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

Function get_instance_fallback

mypy/inspections.py:60–84  ·  view source on GitHub ↗

Returns the Instance fallback for this type if one exists or None.

(typ: ProperType)

Source from the content-addressed store, hash-verified

58
59
60def 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
87def find_node(name: str, info: TypeInfo) -> Var | FuncBase | None:

Callers 2

expr_attrsMethod · 0.85
collect_nodesMethod · 0.85

Calls 4

tuple_fallbackFunction · 0.90
get_proper_typeFunction · 0.90
isinstanceFunction · 0.85
extendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…