class documentation

class Const(Literal):

View In Hierarchy

All constant values. The parser will return this node for simple constants such as 42 or "foo" but it can be used to store more complex values such as lists too. Only constants with a safe representation (objects where eval(repr(x)) == x is true).
Class Method from​_untrusted Return a const object if the value is representable as constant value in the generated code, otherwise it will raise an Impossible exception.
Method as​_const Return the value of the expression as constant or raise Impossible if this was not possible.
Class Variable fields Undocumented
Class Variable value Undocumented

Inherited from Literal:

Class Variable abstract Undocumented

Inherited from Expr (via Literal):

Method can​_assign Check if it's possible to assign something to this node.

Inherited from Node (via Literal, Expr):

Method find Find the first node of a given type. If no such node exists the return value is None.
Method find​_all Find all the nodes of a given type. If the type is a tuple, the check is performed for any of the tuple items.
Method iter​_child​_nodes Iterates over all direct child nodes of the node. This iterates over all fields and yields the values of they are nodes. If the value of a field is a list all the nodes in that list are returned.
Method iter​_fields No summary
Method set​_ctx No summary
Method set​_environment Set the environment for all nodes.
Method set​_lineno Set the line numbers of the node and children.
Method __eq__ Undocumented
Method __init__ Undocumented
Method __repr__ Undocumented
Method dump Undocumented
Class Variable attributes Undocumented
Class Variable environment Undocumented
Class Variable lineno Undocumented
@classmethod
def from_untrusted(cls, value, lineno=None, environment=None):
Return a const object if the value is representable as constant value in the generated code, otherwise it will raise an Impossible exception.
Parameters
value:t.AnyUndocumented
lineno:t.Optional[int]Undocumented
environment:t.Optional[Environment]Undocumented
Returns
ConstUndocumented
def as_const(self, eval_ctx=None):

Return the value of the expression as constant or raise Impossible if this was not possible.

An EvalContext can be provided, if none is given a default context is created which requires the nodes to have an attached environment.

Changed in version 2.4: the eval_ctx parameter was added.
Parameters
eval​_ctx:t.Optional[EvalContext]Undocumented
Returns
t.AnyUndocumented
fields: tuple[str, ...] =

Undocumented

value: t.Any =

Undocumented