MCPcopy
hub / github.com/pytest-dev/pytest / _write_pyc_fp

Function _write_pyc_fp

src/_pytest/assertion/rewrite.py:300–315  ·  src/_pytest/assertion/rewrite.py::_write_pyc_fp
(
    fp: IO[bytes], source_stat: os.stat_result, co: types.CodeType
)

Source from the content-addressed store, hash-verified

298
299
300def _write_pyc_fp(
301 fp: IO[bytes], source_stat: os.stat_result, co: types.CodeType
302) -> None:
303 class="cm"># Technically, we don't have to have the same pyc format as
304 class="cm"># (C)Python, since these class="st">"pycs" should never be seen by builtin
305 class="cm"># import. However, there's little reason to deviate.
306 fp.write(importlib.util.MAGIC_NUMBER)
307 class="cm"># https://www.python.org/dev/peps/pep-0552/
308 flags = bclass="st">"\x00\x00\x00\x00"
309 fp.write(flags)
310 class="cm"># as of now, bytecode header expects 32-bit numbers for size and mtime (#4903)
311 mtime = int(source_stat.st_mtime) & 0xFFFFFFFF
312 size = source_stat.st_size & 0xFFFFFFFF
313 class="cm"># class="st">"<LL" stands for 2 unsigned longs, little-endian.
314 fp.write(struct.pack(class="st">"<LL", mtime, size))
315 fp.write(marshal.dumps(co))
316
317
318def _write_pyc(

Callers 1

_write_pycFunction · 0.85

Calls 3

intClass · 0.85
dumpsMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected