LaxUndefined #67

wants to merge 3 commits into


None yet

3 participants

cwillu commented Oct 11, 2011

In many situations, it is preferable to hobble along (or even make only passing notice) when errors occur rather than blowing up the rendering completely.

My particular case is templates which are created by non-technical users in inkscape. I have found over the last year or so that clear but self-contained effects are desirable in this role.

I do have a continuing issue though, where iteration occasionally trips over the concat implementation in utils; runtime contains a suitable replacement (unicode_join becomes the initial _concat implementation instead of u"".join), but an alternative would be for LaxUndefined to inherit from unicode instead of Undefined, and registering itself on Undefined's new metaclass. I'm not sure which you would find more palatable.


cwillu added some commits Oct 11, 2011
@cwillu cwillu Give Undefined an ABCMeta metaclass, which allows reimplementations o…
…f Undefined to appear to inherit from Undefined, while not actually subclassing it. This removes the restrictions that including a __slots__ member introduces.
@cwillu cwillu Add LaxUndefined, which takes the null-object pattern to the most con…
…venient extreme.

Nearly all operations that would raise an exception under Defined will return self instead, while still preserving the original hint data, which is delivered in the object's repr.
@cwillu cwillu Edited jinja2/ via GitHub 512729e
snoack commented Oct 11, 2011

The abc module was added in Python 2.6. But jinja2 is compatible with Python 2.4. So you have to add a fallback for the case that importing abc fails.


Not sure what the reason for the metaclass is exactly. Why does it have to be an ABC?


Ideally this can just stay in user's code.

@mitsuhiko mitsuhiko closed this May 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment