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

Function _encode_int_values

mypyc/codegen/literals.py:236–257  ·  view source on GitHub ↗

Encode int values into C strings. Values are stored in base 10 and separated by 0 bytes.

(values: dict[int, int])

Source from the content-addressed store, hash-verified

234
235
236def _encode_int_values(values: dict[int, int]) -> list[bytes]:
237 """Encode int values into C strings.
238
239 Values are stored in base 10 and separated by 0 bytes.
240 """
241 value_by_index = {index: value for value, index in values.items()}
242 result = []
243 line: list[bytes] = []
244 line_len = 0
245 for i in range(len(values)):
246 value = value_by_index[i]
247 encoded = b"%d" % value
248 if line_len > 0 and line_len + len(encoded) > 70:
249 result.append(format_int(len(line)) + b"\0".join(line))
250 line = []
251 line_len = 0
252 line.append(encoded)
253 line_len += len(encoded)
254 if line:
255 result.append(format_int(len(line)) + b"\0".join(line))
256 result.append(b"")
257 return result
258
259
260def float_to_c(x: float) -> str:

Callers 2

encoded_int_valuesMethod · 0.85

Calls 6

rangeClass · 0.85
lenFunction · 0.85
format_intFunction · 0.85
appendMethod · 0.80
itemsMethod · 0.45
joinMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…