Convert ConversionSpecifier to FormatOp. Different ConversionSpecifiers may share a same FormatOp.
(specifiers: list[ConversionSpecifier])
| 46 | |
| 47 | |
| 48 | def generate_format_ops(specifiers: list[ConversionSpecifier]) -> list[FormatOp] | None: |
| 49 | """Convert ConversionSpecifier to FormatOp. |
| 50 | |
| 51 | Different ConversionSpecifiers may share a same FormatOp. |
| 52 | """ |
| 53 | format_ops = [] |
| 54 | for spec in specifiers: |
| 55 | # TODO: Match specifiers instead of using whole_seq |
| 56 | if spec.whole_seq == "%s" or spec.whole_seq == "{:{}}": |
| 57 | format_op = FormatOp.STR |
| 58 | elif spec.whole_seq == "%d": |
| 59 | format_op = FormatOp.INT |
| 60 | elif spec.whole_seq == "%b": |
| 61 | format_op = FormatOp.BYTES |
| 62 | elif spec.whole_seq: |
| 63 | return None |
| 64 | else: |
| 65 | format_op = FormatOp.STR |
| 66 | format_ops.append(format_op) |
| 67 | return format_ops |
| 68 | |
| 69 | |
| 70 | def tokenizer_printf_style(format_str: str) -> tuple[list[str], list[FormatOp]] | None: |
no test coverage detected
searching dependent graphs…