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

Function literal

mypy/literals.py:118–150  ·  view source on GitHub ↗

Return the literal kind for an expression.

(e: Expression)

Source from the content-addressed store, hash-verified

116
117
118def literal(e: Expression) -> int:
119 """Return the literal kind for an expression."""
120
121 if isinstance(e, ComparisonExpr):
122 return min(literal(o) for o in e.operands)
123
124 elif isinstance(e, OpExpr):
125 return min(literal(e.left), literal(e.right))
126
127 elif isinstance(e, (MemberExpr, UnaryExpr, StarExpr)):
128 return literal(e.expr)
129
130 elif isinstance(e, AssignmentExpr):
131 return literal(e.target)
132
133 elif isinstance(e, IndexExpr):
134 if literal(e.index) == LITERAL_YES:
135 return literal(e.base)
136 else:
137 return LITERAL_NO
138
139 elif isinstance(e, NameExpr):
140 if isinstance(e.node, Var) and e.node.is_final and e.node.final_value is not None:
141 return LITERAL_YES
142 return LITERAL_TYPE
143
144 if isinstance(e, (IntExpr, FloatExpr, ComplexExpr, StrExpr, BytesExpr)):
145 return LITERAL_YES
146
147 if literal_hash(e):
148 return LITERAL_YES
149
150 return LITERAL_NO
151
152
153def subkeys(key: Key) -> Iterable[Key]:

Callers 11

is_len_of_tupleMethod · 0.90
can_put_directlyMethod · 0.90
putMethod · 0.90
assign_typeMethod · 0.90
seq_exprMethod · 0.85
visit_dict_exprMethod · 0.85
visit_index_exprMethod · 0.85

Calls 3

isinstanceFunction · 0.85
minFunction · 0.85
literal_hashFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…