(
name: str,
itype: Instance,
subtype: Type,
*,
is_operator: bool = False,
class_obj: bool = False,
is_lvalue: bool = False,
)
| 1329 | |
| 1330 | |
| 1331 | def find_member( |
| 1332 | name: str, |
| 1333 | itype: Instance, |
| 1334 | subtype: Type, |
| 1335 | *, |
| 1336 | is_operator: bool = False, |
| 1337 | class_obj: bool = False, |
| 1338 | is_lvalue: bool = False, |
| 1339 | ) -> Type | None: |
| 1340 | type_checker = checker_state.type_checker |
| 1341 | if type_checker is None: |
| 1342 | # Unfortunately, there are many scenarios where someone calls is_subtype() before |
| 1343 | # type checking phase. In this case we fallback to old (incomplete) logic. |
| 1344 | # TODO: reduce number of such cases (e.g. semanal_typeargs, post-semanal plugins). |
| 1345 | return find_member_simple( |
| 1346 | name, itype, subtype, is_operator=is_operator, class_obj=class_obj, is_lvalue=is_lvalue |
| 1347 | ) |
| 1348 | |
| 1349 | # We don't use ATTR_DEFINED error code below (since missing attributes can cause various |
| 1350 | # other error codes), instead we perform quick node lookup with all the fallbacks. |
| 1351 | info = itype.type |
| 1352 | sym = info.get(name) |
| 1353 | node = sym.node if sym else None |
| 1354 | if not node: |
| 1355 | name_not_found = True |
| 1356 | if ( |
| 1357 | name not in ["__getattr__", "__setattr__", "__getattribute__"] |
| 1358 | and not is_operator |
| 1359 | and not class_obj |
| 1360 | and itype.extra_attrs is None # skip ModuleType.__getattr__ |
| 1361 | ): |
| 1362 | for method_name in ("__getattribute__", "__getattr__"): |
| 1363 | method = info.get_method(method_name) |
| 1364 | if method and method.info.fullname != "builtins.object": |
| 1365 | name_not_found = False |
| 1366 | break |
| 1367 | if name_not_found: |
| 1368 | if info.fallback_to_any or class_obj and info.meta_fallback_to_any: |
| 1369 | return AnyType(TypeOfAny.special_form) |
| 1370 | if itype.extra_attrs and name in itype.extra_attrs.attrs: |
| 1371 | return itype.extra_attrs.attrs[name] |
| 1372 | return None |
| 1373 | |
| 1374 | from mypy.checkmember import ( |
| 1375 | MemberContext, |
| 1376 | analyze_class_attribute_access, |
| 1377 | analyze_instance_member_access, |
| 1378 | ) |
| 1379 | |
| 1380 | mx = MemberContext( |
| 1381 | is_lvalue=is_lvalue, |
| 1382 | is_super=False, |
| 1383 | is_operator=is_operator, |
| 1384 | original_type=TypeType.make_normalized(itype) if class_obj else itype, |
| 1385 | self_type=TypeType.make_normalized(subtype) if class_obj else subtype, |
| 1386 | context=Context(), # all errors are filtered, but this is a required argument |
| 1387 | chk=type_checker, |
| 1388 | suppress_errors=True, |
no test coverage detected
searching dependent graphs…