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

Function tokenizer_printf_style

mypyc/irbuild/format_str_tokenizer.py:70–89  ·  view source on GitHub ↗

Tokenize a printf-style format string using regex. Return: A list of string literals and a list of FormatOps.

(format_str: str)

Source from the content-addressed store, hash-verified

68
69
70def tokenizer_printf_style(format_str: str) -> tuple[list[str], list[FormatOp]] | None:
71 """Tokenize a printf-style format string using regex.
72
73 Return:
74 A list of string literals and a list of FormatOps.
75 """
76 literals: list[str] = []
77 specifiers: list[ConversionSpecifier] = parse_conversion_specifiers(format_str)
78 format_ops = generate_format_ops(specifiers)
79 if format_ops is None:
80 return None
81
82 last_end = 0
83 for spec in specifiers:
84 cur_start = spec.start_pos
85 literals.append(format_str[last_end:cur_start])
86 last_end = cur_start + len(spec.whole_seq)
87 literals.append(format_str[last_end:])
88
89 return literals, format_ops
90
91
92# The empty Context as an argument for parse_format_value().

Callers 1

Calls 4

generate_format_opsFunction · 0.85
lenFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…