implementedBy() is broken in Python 3.2
Bug #911851 reported by
Barry Warsaw
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
zope.interface |
Won't Fix
|
Undecided
|
Unassigned |
Bug Description
While porting some existing code using zope.interface to Python 3.2, I noticed that Interface.
from __future__ import print_function
__metaclass__ = type
from zope.interface import Interface, implements
class MyInterface(
pass
class MyClass:
implements(
print(MyInterfa
I think the reason is that MyClass doesn't end up with an __implements__ attribute, but I'm not sure why that is.
To post a comment you must log in.
This is a know problem with the "class advice" mechanism used for
'implements', 'implementsOnly', and 'classProvides': they abuse the stack
frame to mutate the locals of their suite in a way which doesn't work in Py3k.
The (portable) workaround is to use the 'implementer' ('implementor_only' /
'provider') class decorators::
from zope.interface import implementer
@implementer( MyInterface)
class MyClass(object):
pass
"Portable" obviously only includes Py2 versions which support class
decorators (>= 2.6).