MCPcopy
hub / github.com/python/mypy / write_literal

Function write_literal

mypy/cache.py:347–364  ·  view source on GitHub ↗
(data: WriteBuffer, value: int | str | bool | float | complex | None)

Source from the content-addressed store, hash-verified

345# There is an intentional asymmetry between read and write for literals because
346# None and/or complex values are only allowed in some contexts but not in others.
347def write_literal(data: WriteBuffer, value: int | str | bool | float | complex | None) -> None:
348 if isinstance(value, bool):
349 write_bool(data, value)
350 elif isinstance(value, int):
351 write_tag(data, LITERAL_INT)
352 write_int_bare(data, value)
353 elif isinstance(value, str):
354 write_tag(data, LITERAL_STR)
355 write_str_bare(data, value)
356 elif isinstance(value, float):
357 write_tag(data, LITERAL_FLOAT)
358 write_float_bare(data, value)
359 elif isinstance(value, complex):
360 write_tag(data, LITERAL_COMPLEX)
361 write_float_bare(data, value.real)
362 write_float_bare(data, value.imag)
363 else:
364 write_tag(data, LITERAL_NONE)
365
366
367def read_int(data: ReadBuffer) -> int:

Callers 2

writeMethod · 0.90
writeMethod · 0.90

Calls 1

isinstanceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…