OpenQuizz
Une application de gestion des contenus pédagogiques
Const Class Reference
Inheritance diagram for Const:
Collaboration diagram for Const:

Public Member Functions

def as_const (self, eval_ctx=None)
 
def from_untrusted (cls, value, lineno=None, environment=None)
 
- Public Member Functions inherited from Expr
def can_assign (self)
 
- Public Member Functions inherited from Node
def __init__ (self, *fields, **attributes)
 
def iter_fields (self, exclude=None, only=None)
 
def iter_child_nodes (self, exclude=None, only=None)
 
def find (self, node_type)
 
def find_all (self, node_type)
 
def set_ctx (self, ctx)
 
def set_lineno (self, lineno, override=False)
 
def set_environment (self, environment)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __repr__ (self)
 
def dump (self)
 
- Public Member Functions inherited from NodeType
def __new__ (mcs, name, bases, d)
 

Static Public Attributes

 fields
 
- Static Public Attributes inherited from Literal
 abstract
 
- Static Public Attributes inherited from Expr
 abstract
 
- Static Public Attributes inherited from Node
 fields
 
 attributes
 
 abstract
 

Detailed Description

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).

Member Function Documentation

◆ as_const()

def as_const (   self,
  eval_ctx = None 
)
Return the value of the expression as constant or raise
:exc:`Impossible` if this was not possible.

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

.. versionchanged:: 2.4
   the `eval_ctx` parameter was added.

Reimplemented from Expr.

◆ from_untrusted()

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.

Field Documentation

◆ fields

fields
static

The documentation for this class was generated from the following file: