| 1672 | |
| 1673 | # FormattedValue(expr value) |
| 1674 | def visit_FormattedValue(self, n: ast3.FormattedValue) -> Expression: |
| 1675 | # A FormattedValue is a component of a JoinedStr, or it can exist |
| 1676 | # on its own. We translate them to individual '{}'.format(value) |
| 1677 | # calls. Format specifier and conversion information is passed along |
| 1678 | # to allow mypyc to support f-strings with format specifiers and conversions. |
| 1679 | val_exp = self.visit(n.value) |
| 1680 | val_exp.set_line(n.lineno, n.col_offset) |
| 1681 | conv_str = "" if n.conversion < 0 else "!" + chr(n.conversion) |
| 1682 | format_string = StrExpr("{" + conv_str + ":{}}") |
| 1683 | format_spec_exp = self.visit(n.format_spec) if n.format_spec is not None else StrExpr("") |
| 1684 | format_string.set_line(n.lineno, n.col_offset) |
| 1685 | format_method = MemberExpr(format_string, "format") |
| 1686 | format_method.set_line(format_string) |
| 1687 | result_expression = CallExpr( |
| 1688 | format_method, [val_exp, format_spec_exp], [ARG_POS, ARG_POS], [None, None] |
| 1689 | ) |
| 1690 | return self.set_line(result_expression, n) |
| 1691 | |
| 1692 | # TemplateStr(expr* values) |
| 1693 | def visit_TemplateStr(self, n: ast_TemplateStr) -> TemplateStrExpr: |