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

Function read_expression

mypy/nativeparse.py:1236–1569  ·  view source on GitHub ↗
(state: State, data: ReadBuffer)

Source from the content-addressed store, hash-verified

1234
1235
1236def read_expression(state: State, data: ReadBuffer) -> Expression:
1237 # Branches ordered by frequency (based on mypy self-check)
1238 tag = read_tag(data)
1239 expr: Expression
1240 if tag == nodes.NAME_EXPR:
1241 s = read_str(data)
1242 ne = NameExpr(s)
1243 read_loc(data, ne)
1244 expect_end_tag(data)
1245 return ne
1246 elif tag == nodes.MEMBER_EXPR:
1247 e = read_expression(state, data)
1248 attr = read_str(data)
1249 m = MemberExpr(e, attr)
1250 # Check if this is a super() call - if so, convert to SuperExpr
1251 if isinstance(e, CallExpr) and isinstance(e.callee, NameExpr) and e.callee.name == "super":
1252 result: Expression = SuperExpr(attr, e)
1253 else:
1254 result = m
1255 read_loc(data, result)
1256 expect_end_tag(data)
1257 return result
1258 elif tag == nodes.CALL_EXPR:
1259 callee = read_expression(state, data)
1260 args = read_expression_list(state, data)
1261 # Read argument kinds
1262 expect_tag(data, LIST_INT)
1263 n_kinds = read_int_bare(data)
1264 arg_kinds = [ARG_KINDS[read_int_bare(data)] for _ in range(n_kinds)]
1265 # Read argument names
1266 expect_tag(data, LIST_GEN)
1267 n_names = read_int_bare(data)
1268 arg_names: list[str | None] = []
1269 for _ in range(n_names):
1270 tag = read_tag(data)
1271 if tag == LITERAL_NONE:
1272 arg_names.append(None)
1273 elif tag == LITERAL_STR:
1274 arg_names.append(read_str_bare(data))
1275 else:
1276 assert False, f"Unexpected tag for arg_name: {tag}"
1277 ce = CallExpr(callee, args, arg_kinds, arg_names)
1278 read_loc(data, ce)
1279 expect_end_tag(data)
1280 return ce
1281 elif tag == nodes.STR_EXPR:
1282 se = StrExpr(read_str(data))
1283 read_loc(data, se)
1284 expect_end_tag(data)
1285 return se
1286 elif tag == nodes.COMPARISON_EXPR:
1287 left = read_expression(state, data)
1288 expect_tag(data, LIST_INT)
1289 n_ops = read_int_bare(data)
1290 ops = [cmp_ops[read_int_bare(data)] for _ in range(n_ops)]
1291 comparators = read_expression_list(state, data)
1292 assert len(ops) == len(comparators)
1293 expr = ComparisonExpr(ops, [left] + comparators)

Callers 9

read_statementFunction · 0.85
read_parametersFunction · 0.85
read_class_defFunction · 0.85
read_type_alias_stmtFunction · 0.85
read_try_stmtFunction · 0.85
read_patternFunction · 0.85
read_fstring_itemFunction · 0.85
read_expression_listFunction · 0.85
read_generator_exprFunction · 0.85

Calls 15

read_strFunction · 0.90
NameExprClass · 0.90
MemberExprClass · 0.90
SuperExprClass · 0.90
CallExprClass · 0.90
StrExprClass · 0.90
ComparisonExprClass · 0.90
IntExprClass · 0.90
read_intFunction · 0.90
IndexExprClass · 0.90
ListExprClass · 0.90
TupleExprClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…