Adding a _frame argument to InterfaceClass.__init__ to make it subclassable
Laurence Rowe <[email protected]>
| Newsgroups | gmane.comp.web.zope.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, I'd like to apply the attached patch to zope.interface trunk to make it more easily subclassable without having to copy and paste a chunk of its __init__ into the subclass' __init__. Motivating factor is: I need an Interface with a hook that gets called after InterfaceClass.__init__ to allow for: * Checking that field names supplied as tagged values from directives correspond to actual field names to detect typos. * Registering the Interface instance for further configuration to be executed by a zope.configuration action. (Subclass is http://dev.plone.org/plone/browser/plone.supermodel/branches/elro-directives/plone/supermodel/model.py#L52) Laurence _______________________________________________ Zope-Dev maillist - [email protected] https://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope )
InterfaceClass-frame.diff
(application/octet-stream, 920 B)
Index: src/zope/interface/interface.py
===================================================================
--- src/zope/interface/interface.py (revision 121491)
+++ src/zope/interface/interface.py (working copy)
@@ -434,7 +434,7 @@
#implements(IInterface)
def __init__(self, name, bases=(), attrs=None, __doc__=None,
- __module__=None):
+ __module__=None, _frame=1):
if attrs is None:
attrs = {}
@@ -448,7 +448,7 @@
# Figure out what module defined the interface.
# This is how cPython figures out the module of
# a class, but of course it does it in C. :-/
- __module__ = sys._getframe(1).f_globals['__name__']
+ __module__ = sys._getframe(_frame).f_globals['__name__']
except (AttributeError, KeyError):
pass