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

Function generate_format_ops

mypyc/irbuild/format_str_tokenizer.py:48–67  ·  view source on GitHub ↗

Convert ConversionSpecifier to FormatOp. Different ConversionSpecifiers may share a same FormatOp.

(specifiers: list[ConversionSpecifier])

Source from the content-addressed store, hash-verified

46
47
48def 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
70def tokenizer_printf_style(format_str: str) -> tuple[list[str], list[FormatOp]] | None:

Callers 2

tokenizer_printf_styleFunction · 0.85
tokenizer_format_callFunction · 0.85

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…