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

Function analyze_enum_class_attribute_access

mypy/checkmember.py:1352–1374  ·  view source on GitHub ↗
(
    itype: Instance, name: str, mx: MemberContext
)

Source from the content-addressed store, hash-verified

1350
1351
1352def analyze_enum_class_attribute_access(
1353 itype: Instance, name: str, mx: MemberContext
1354) -> Type | None:
1355 # Skip these since Enum will remove it
1356 if name in EXCLUDED_ENUM_ATTRIBUTES:
1357 return report_missing_attribute(mx.original_type, itype, name, mx)
1358
1359 node = itype.type.get(name)
1360 if node and node.type:
1361 proper = get_proper_type(node.type)
1362 # Support `A = nonmember(1)` function call and decorator.
1363 if (
1364 isinstance(proper, Instance)
1365 and proper.type.fullname == "enum.nonmember"
1366 and proper.args
1367 ):
1368 return proper.args[0]
1369
1370 if name not in itype.type.enum_members:
1371 return None
1372
1373 enum_literal = LiteralType(name, fallback=itype)
1374 return itype.copy_modified(last_known_value=enum_literal)
1375
1376
1377def analyze_typeddict_access(

Callers 1

Calls 6

get_proper_typeFunction · 0.90
LiteralTypeClass · 0.90
report_missing_attributeFunction · 0.85
isinstanceFunction · 0.85
getMethod · 0.45
copy_modifiedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…