Package genshi :: Package template :: Module eval :: Class Undefined

Class Undefined

object --+
         |
        Undefined

Represents a reference to an undefined variable.

Unlike the Python runtime, template expressions can refer to an undefined variable without causing a NameError to be raised. The result will be an instance of the Undefined class, which is treated the same as False in conditions, but raise an exception on any other operation:

>>> foo = Undefined('foo')
>>> bool(foo)
False
>>> list(foo)
[]
>>> print(foo)
undefined

However, calling an undefined variable, or trying to access an attribute of that variable, will raise an exception that includes the name used to reference that undefined variable.

>>> foo('bar')
Traceback (most recent call last):
    ...
UndefinedError: "foo" not defined
>>> foo.bar
Traceback (most recent call last):
    ...
UndefinedError: "foo" not defined

See Also: LenientLookup

Instance Methods
 
__init__(self, name, owner=UNDEFINED)
Initialize the object.
 
__iter__(self)
 
__nonzero__(self)
 
__repr__(self)
repr(x)
 
__str__(self)
str(x)
 
__getitem__(self, *args, **kwargs)
Raise an UndefinedError.
 
__getattr__(self, *args, **kwargs)
Raise an UndefinedError.
 
__call__(self, *args, **kwargs)
Raise an UndefinedError.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Class Variables
  __length_hint__ = None
hash(x)
Properties

Inherited from object: __class__

Method Details

__init__(self, name, owner=UNDEFINED)
(Constructor)

 
Initialize the object.
Parameters:
  • name - the name of the reference
  • owner - the owning object, if the variable is accessed as a member
Overrides: object.__init__

__repr__(self)
(Representation operator)

 
repr(x)
Overrides: object.__repr__
(inherited documentation)

__str__(self)
(Informal representation operator)

 
str(x)
Overrides: object.__str__
(inherited documentation)