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

Method process_enum_call

mypy/semanal_enum.py:63–81  ·  view source on GitHub ↗

Check if s defines an Enum; if yes, store the definition in symbol table. Return True if this looks like an Enum definition (but maybe with errors), otherwise return False.

(self, s: AssignmentStmt, is_func_scope: bool)

Source from the content-addressed store, hash-verified

61 self.api = api
62
63 def process_enum_call(self, s: AssignmentStmt, is_func_scope: bool) -> bool:
64 """Check if s defines an Enum; if yes, store the definition in symbol table.
65
66 Return True if this looks like an Enum definition (but maybe with errors),
67 otherwise return False.
68 """
69 if len(s.lvalues) != 1 or not isinstance(s.lvalues[0], (NameExpr, MemberExpr)):
70 return False
71 lvalue = s.lvalues[0]
72 name = lvalue.name
73 enum_call = self.check_enum_call(s.rvalue, name, is_func_scope)
74 if enum_call is None:
75 return False
76 if isinstance(lvalue, MemberExpr):
77 self.fail("Enum type as attribute is not supported", lvalue)
78 return False
79 # Yes, it's a valid Enum definition. Add it to the symbol table.
80 self.api.add_symbol(name, enum_call, s)
81 return True
82
83 def check_enum_call(
84 self, node: Expression, var_name: str, is_func_scope: bool

Callers 1

analyze_enum_assignMethod · 0.80

Calls 5

check_enum_callMethod · 0.95
failMethod · 0.95
lenFunction · 0.85
isinstanceFunction · 0.85
add_symbolMethod · 0.45

Tested by

no test coverage detected