(state: State, data: ReadBuffer)
| 1609 | |
| 1610 | |
| 1611 | def 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 | |
| 1645 | def set_line_column(target: Context, src: Context) -> None: |
no test coverage detected
searching dependent graphs…