This module implements constant folding on the AST. It handles simple cases such as

  • 1 + 2 -> 3

  • 2 ** 10 -> 1024

  • N=1; N + 1 -> 2 (for N is assigned as global variable or a variable

    that’s only assigned once)

class numba.ast_constant_folding.ConstantFolder(*args, **kws)

Perform constant folding on AST.

NOTE: Forbids assignment to True, False, None.

eval_binary_operation(op, left, right)

Evaluate the constant expression and return a ast.Num instance containing the result.


Get constant value from AST node.


Store the rhs value so we can inline them in future reference.

TODO: Remove assignment of constant

class numba.ast_constant_folding.ConstantMarker(*args, **kws)

A conservative constant marker. Conservative because we handle the simplest cases only.


Return a set of constant variable names

Previous topic


Next topic


This Page