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

Function try_constant_fold

mypyc/irbuild/expression.py:792–800  ·  view source on GitHub ↗

Return the constant value of an expression if possible. Return None otherwise.

(builder: IRBuilder, expr: Expression)

Source from the content-addressed store, hash-verified

790
791
792def try_constant_fold(builder: IRBuilder, expr: Expression) -> Value | None:
793 """Return the constant value of an expression if possible.
794
795 Return None otherwise.
796 """
797 value = constant_fold_expr(builder, expr)
798 if value is not None:
799 return builder.load_literal_value(value)
800 return None
801
802
803def try_gen_slice_op(builder: IRBuilder, base: Value, index: SliceExpr) -> Value | None:

Callers 2

transform_unary_exprFunction · 0.85
transform_op_exprFunction · 0.85

Calls 2

constant_fold_exprFunction · 0.90
load_literal_valueMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…