# HG changeset patch # User cmlenz # Date 1165838788 0 # Node ID 31dc3d18b39e622ef1eeef297478b42beec7763c # Parent a52452a65cd7f11b72088ff50a1ad09abcbf6851 0.3.x branch: add unit test for `Undefined` checks in template expressions. diff --git a/genshi/eval.py b/genshi/eval.py --- a/genshi/eval.py +++ b/genshi/eval.py @@ -61,6 +61,15 @@ >>> data = dict(items=[1, 2, 3]) >>> Expression('len(items)').evaluate(data) 3 + + Undefined variables can be accessed in expressions, and evaluate to a + non-truth value for tests. To check whether a particular variable is + defined, its type can be compared to the special builtin class `Undefined`: + + >>> Expression('foo').evaluate({}) + undefined + >>> Expression('type(foo) is Undefined').evaluate({}) + True """ __slots__ = ['source', 'code']