NodeBase metaclass check logic is faulty
|Reported by:||(removed)||Owned by:||adrian|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
As hinted at on the ml, the NodeBase.new code is a bit faulty-
def __new__(cls, name, bases, attrs): """ Ensures that either a 'render' or 'render_iter' method is defined on any Node sub-class. This avoids potential infinite loops at runtime. """ if not (isinstance(attrs.get('render'), types.FunctionType) or isinstance(attrs.get('iter_render'), types.FunctionType)): raise TypeError('Unable to create Node subclass without either "render" or "iter_render" method.') return type.__new__(cls, name, bases, attrs)
1) for code that has already broken the iter_render/render cycle, each derivative *still* has to assign a render/iter_render else it'll invalidly explode
2) no way to disable it (intermediate direct descendants from Node, say, adding helper functionality- they expect render/iter_render to be overriden, but the rules don't apply to them).
Attached is a patch that converts the check over to verifying the resultant (as in, full MRO) render/iter_render, and adds an option to specifically disable the verification where needed.