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

Function join_formatted_bytes

mypyc/irbuild/format_str_tokenizer.py:239–260  ·  view source on GitHub ↗

Merge the list of literals and the list of substitutions alternatively using 'bytes_build_op'.

(
    builder: IRBuilder, literals: list[str], substitutions: list[Value], line: int
)

Source from the content-addressed store, hash-verified

237
238
239def join_formatted_bytes(
240 builder: IRBuilder, literals: list[str], substitutions: list[Value], line: int
241) -> Value:
242 """Merge the list of literals and the list of substitutions
243 alternatively using 'bytes_build_op'."""
244 result_list: list[Value] = [Integer(0, c_pyssize_t_rprimitive)]
245
246 for a, b in zip(literals, substitutions):
247 if a:
248 result_list.append(builder.load_bytes_from_str_literal(a))
249 result_list.append(b)
250 if literals[-1]:
251 result_list.append(builder.load_bytes_from_str_literal(literals[-1]))
252
253 # Special case for empty bytes and literal
254 if len(result_list) == 1:
255 return builder.load_bytes_from_str_literal("")
256 if not substitutions and len(result_list) == 2:
257 return result_list[1]
258
259 result_list[0] = Integer(len(result_list) - 1, c_pyssize_t_rprimitive)
260 return builder.call_c(bytes_build_op, result_list, line)

Callers 1

Calls 6

IntegerClass · 0.90
zipFunction · 0.85
lenFunction · 0.85
appendMethod · 0.80
call_cMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…