MCPcopy Index your code
hub / github.com/RustPython/RustPython / randrange_fmt

Function randrange_fmt

Lib/test/test_buffer.py:164–178  ·  view source on GitHub ↗

Return random item for a type specified by a mode and a single format character.

(mode, char, obj)

Source from the content-addressed store, hash-verified

162}
163
164def randrange_fmt(mode, char, obj):
165 """Return random item for a type specified by a mode and a single
166 format character."""
167 x = randrange(*fmtdict[mode][char])
168 if char == 'c':
169 x = bytes([x])
170 if obj == 'numpy' and x == b'\x00':
171 # https://github.com/numpy/numpy/issues/2518
172 x = b'\x01'
173 if char == '?':
174 x = bool(x)
175 if char in 'efd':
176 x = struct.pack(char, x)
177 x = struct.unpack(char, x)[0]
178 return x
179
180def gen_item(fmt, obj):
181 """Return single random item."""

Callers 1

gen_itemFunction · 0.85

Calls 2

packMethod · 0.45
unpackMethod · 0.45

Tested by

no test coverage detected