LaxUndefined #67

Closed
wants to merge 3 commits into
from

Conversation

3 participants
@cwillu

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.

Cheers
--cwillu

cwillu added some commits Oct 11, 2011

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.
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.
@snoack

This comment has been minimized.

Show comment Hide comment
@snoack

snoack Oct 11, 2011

Contributor

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.

Contributor

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.

@mitsuhiko

This comment has been minimized.

Show comment Hide comment
@mitsuhiko

mitsuhiko Oct 11, 2011

Member

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

Member

mitsuhiko commented Oct 11, 2011

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

@mitsuhiko

This comment has been minimized.

Show comment Hide comment
@mitsuhiko

mitsuhiko May 19, 2013

Member

Ideally this can just stay in user's code.

Member

mitsuhiko commented May 19, 2013

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