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

Function _extract_python_literal

mypyc/ir/func_ir.py:465–484  ·  view source on GitHub ↗
(value: Value)

Source from the content-addressed store, hash-verified

463
464
465def _extract_python_literal(value: Value) -> object:
466 if isinstance(value, Integer):
467 if is_none_rprimitive(value.type):
468 return None
469 val = value.numeric_value()
470 if is_bool_rprimitive(value.type):
471 return bool(val)
472 return val
473 elif isinstance(value, Float):
474 return value.value
475 elif isinstance(value, LoadLiteral):
476 return value.value
477 elif isinstance(value, Box):
478 return _extract_python_literal(value.src)
479 elif isinstance(value, TupleSet):
480 items = tuple(_extract_python_literal(item) for item in value.items)
481 if any(itm is _NOT_REPRESENTABLE for itm in items):
482 return _NOT_REPRESENTABLE
483 return items
484 return _NOT_REPRESENTABLE

Callers 1

_find_default_argumentFunction · 0.85

Calls 7

is_none_rprimitiveFunction · 0.90
is_bool_rprimitiveFunction · 0.90
isinstanceFunction · 0.85
boolClass · 0.85
tupleClass · 0.85
anyFunction · 0.85
numeric_valueMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…