(
builder: IRBuilder, format_expr: StrExpr | BytesExpr, rhs: Expression
)
| 1098 | |
| 1099 | |
| 1100 | def translate_printf_style_formatting( |
| 1101 | builder: IRBuilder, format_expr: StrExpr | BytesExpr, rhs: Expression |
| 1102 | ) -> Value | None: |
| 1103 | tokens = tokenizer_printf_style(format_expr.value) |
| 1104 | if tokens is not None: |
| 1105 | literals, format_ops = tokens |
| 1106 | |
| 1107 | exprs = [] |
| 1108 | if isinstance(rhs, TupleExpr): |
| 1109 | exprs = rhs.items |
| 1110 | elif isinstance(rhs, Expression): |
| 1111 | exprs.append(rhs) |
| 1112 | |
| 1113 | if isinstance(format_expr, BytesExpr): |
| 1114 | substitutions = convert_format_expr_to_bytes( |
| 1115 | builder, format_ops, exprs, format_expr.line |
| 1116 | ) |
| 1117 | if substitutions is not None: |
| 1118 | return join_formatted_bytes(builder, literals, substitutions, format_expr.line) |
| 1119 | else: |
| 1120 | substitutions = convert_format_expr_to_str( |
| 1121 | builder, format_ops, exprs, format_expr.line |
| 1122 | ) |
| 1123 | if substitutions is not None: |
| 1124 | return join_formatted_strings(builder, literals, substitutions, format_expr.line) |
| 1125 | |
| 1126 | return None |
| 1127 | |
| 1128 | |
| 1129 | # Literals |
no test coverage detected
searching dependent graphs…