Opened 18 years ago
Closed 18 years ago
#4625 closed (fixed)
NodeBase metaclass check logic is faulty
Reported by: | (removed) | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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)
Failings:
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.
Attachments (2)
Change History (3)
by , 18 years ago
Attachment: | render-check-fix.patch added |
---|
by , 18 years ago
Attachment: | render-check-fix.2.patch added |
---|
comment:1 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Fixed via [5511] removal, already fixed in 'upstream' (ie, my branch), thus closing since it won't be reappearing.
working version of the patch (using equality for the func check instead of identity)