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

Function format_int

mypyc/codegen/literals.py:216–228  ·  view source on GitHub ↗

Format an integer using a variable-length binary encoding.

(n: int)

Source from the content-addressed store, hash-verified

214
215
216def format_int(n: int) -> bytes:
217 """Format an integer using a variable-length binary encoding."""
218 if n < 128:
219 a = [n]
220 else:
221 a = []
222 while n > 0:
223 a.insert(0, n & 0x7F)
224 n >>= 7
225 for i in range(len(a) - 1):
226 # If the highest bit is set, more 7-bit digits follow
227 a[i] |= 0x80
228 return bytes(a)
229
230
231def format_str_literal(s: str) -> bytes:

Callers 4

_encode_str_valuesFunction · 0.85
_encode_bytes_valuesFunction · 0.85
format_str_literalFunction · 0.85
_encode_int_valuesFunction · 0.85

Calls 4

rangeClass · 0.85
lenFunction · 0.85
bytesClass · 0.85
insertMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…