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

Function _analyze_member_access

mypy/checkmember.py:242–281  ·  view source on GitHub ↗
(
    name: str, typ: Type, mx: MemberContext, override_info: TypeInfo | None = None
)

Source from the content-addressed store, hash-verified

240
241
242def _analyze_member_access(
243 name: str, typ: Type, mx: MemberContext, override_info: TypeInfo | None = None
244) -> Type:
245 typ = get_proper_type(typ)
246 if isinstance(typ, Instance):
247 return analyze_instance_member_access(name, typ, mx, override_info)
248 elif isinstance(typ, AnyType):
249 # The base object has dynamic type.
250 return AnyType(TypeOfAny.from_another_any, source_any=typ)
251 elif isinstance(typ, UnionType):
252 return analyze_union_member_access(name, typ, mx)
253 elif isinstance(typ, FunctionLike) and typ.is_type_obj():
254 return analyze_type_callable_member_access(name, typ, mx)
255 elif isinstance(typ, TypeType):
256 return analyze_type_type_member_access(name, typ, mx, override_info)
257 elif isinstance(typ, TupleType):
258 # Actually look up from the fallback instance type.
259 return _analyze_member_access(name, tuple_fallback(typ), mx, override_info)
260 elif isinstance(typ, (LiteralType, FunctionLike)):
261 # Actually look up from the fallback instance type.
262 return _analyze_member_access(name, typ.fallback, mx, override_info)
263 elif isinstance(typ, TypedDictType):
264 return analyze_typeddict_access(name, typ, mx, override_info)
265 elif isinstance(typ, NoneType):
266 return analyze_none_member_access(name, typ, mx)
267 elif isinstance(typ, TypeVarLikeType):
268 if isinstance(typ, TypeVarType) and typ.values:
269 return _analyze_member_access(
270 name, make_simplified_union(typ.values), mx, override_info
271 )
272 return _analyze_member_access(name, typ.upper_bound, mx, override_info)
273 elif isinstance(typ, DeletedType):
274 if not mx.suppress_errors:
275 mx.msg.deleted_as_rvalue(typ, mx.context)
276 return AnyType(TypeOfAny.from_error)
277 elif isinstance(typ, UninhabitedType):
278 attr_type = UninhabitedType()
279 attr_type.ambiguous = typ.ambiguous
280 return attr_type
281 return report_missing_attribute(mx.original_type, typ, name, mx)
282
283
284def may_be_awaitable_attribute(

Callers 8

analyze_member_accessFunction · 0.85
analyze_varFunction · 0.85
analyze_typeddict_accessFunction · 0.85

Calls 15

get_proper_typeFunction · 0.90
AnyTypeClass · 0.90
tuple_fallbackFunction · 0.90
make_simplified_unionFunction · 0.90
UninhabitedTypeClass · 0.90
isinstanceFunction · 0.85
analyze_typeddict_accessFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…