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

Function read_fstring_item

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

Source from the content-addressed store, hash-verified

1609
1610
1611def read_fstring_item(state: State, data: ReadBuffer) -> Expression:
1612 t = read_tag(data)
1613 if t == LITERAL_STR:
1614 str_expr = StrExpr(read_str_bare(data))
1615 read_loc(data, str_expr)
1616 return str_expr
1617 elif t == nodes.FSTRING_INTERPOLATION:
1618 expr = read_expression(state, data)
1619
1620 # Read conversion flag such as !r
1621 has_conv = read_bool(data)
1622 if has_conv:
1623 c = read_str(data)
1624 fmt = "{" + c + ":{}}"
1625 else:
1626 fmt = "{:{}}"
1627
1628 # Read format spec such as <30 (which may have nested {...})
1629 has_spec = read_bool(data)
1630 if has_spec:
1631 spec = read_fstring_items(state, data)
1632 else:
1633 spec = StrExpr("")
1634
1635 member = MemberExpr(StrExpr(fmt), "format")
1636 set_line_column(member, expr)
1637 call = CallExpr(member, [expr, spec], [ARG_POS, ARG_POS], [None, None])
1638 set_line_column(call, expr)
1639 expect_end_tag(data)
1640 return call
1641 else:
1642 raise ValueError(f"Unexpected tag {t}")
1643
1644
1645def set_line_column(target: Context, src: Context) -> None:

Callers 2

read_expressionFunction · 0.85
read_fstring_itemsFunction · 0.85

Calls 10

StrExprClass · 0.90
read_strFunction · 0.90
MemberExprClass · 0.90
CallExprClass · 0.90
read_locFunction · 0.85
read_expressionFunction · 0.85
read_fstring_itemsFunction · 0.85
set_line_columnFunction · 0.85
expect_end_tagFunction · 0.85
ValueErrorClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…