# HG changeset patch # User cmlenz # Date 1165838788 0 # Node ID dfb3f9310f2e827790992deef4b1df1472b76a23 # Parent fa0388331cee233174e9fef361cbbb14eb59061a 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']