[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/interface/
Merged from trunk:
Jim Fulton
jim at zope.com
Wed Aug 11 14:35:50 EDT 2004
Log message for revision 27016:
Merged from trunk:
r26975 | jim | 2004-08-10 15:49:07 -0400 (Tue, 10 Aug 2004) | 2 lines
Fixed a bug in getting implements spec for proxied built-in objects.
Changed:
U Zope3/branches/ZopeX3-3.0/src/zope/interface/declarations.py
U Zope3/branches/ZopeX3-3.0/src/zope/interface/tests/test_declarations.py
-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/interface/declarations.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/interface/declarations.py 2004-08-11 18:29:37 UTC (rev 27015)
+++ Zope3/branches/ZopeX3-3.0/src/zope/interface/declarations.py 2004-08-11 18:35:50 UTC (rev 27016)
@@ -380,7 +380,12 @@
spec = getattr(cls, '__implemented__', None)
if spec is None:
+ # There's no spec stred in the class. Maybe its a builtin:
+ spec = BuiltinImplementationSpecifications.get(cls)
+ if spec is not None:
+ return spec
return _empty
+
if spec.__class__ == Implements:
# we defaulted to _empty or there was a spec. Good enough.
# Return it.
Modified: Zope3/branches/ZopeX3-3.0/src/zope/interface/tests/test_declarations.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/interface/tests/test_declarations.py 2004-08-11 18:29:37 UTC (rev 27015)
+++ Zope3/branches/ZopeX3-3.0/src/zope/interface/tests/test_declarations.py 2004-08-11 18:35:50 UTC (rev 27016)
@@ -280,6 +280,39 @@
['IFoo']
"""
+def test_getting_spec_for_proxied_builtin_class():
+ """
+
+ In general, we should be able to get a spec
+ for a proxied class if someone has declared or
+ asked for a spec before.
+
+ We don't want to depend on proxies in this (zope.interface)
+ package, but we do want to work with proxies. Proxies have the
+ effect that a class's __dict__ cannot be gotten. Further, for
+ built-in classes, we can't save, and thus, cannot get, any class
+ attributes. We'll emulate this by treating a plain object as a class:
+
+ >>> cls = object()
+
+ We'll create an implements specification:
+
+ >>> import zope.interface.declarations
+ >>> impl = zope.interface.declarations.Implements(I1, I2)
+
+ Now, we'll emulate a declaration for a built-in type by putting
+ it in BuiltinImplementationSpecifications:
+
+ >>> zope.interface.declarations.BuiltinImplementationSpecifications[
+ ... cls] = impl
+
+ Now, we should be able to get it back:
+
+ >>> implementedBy(cls) is impl
+ True
+
+ """
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(Test))
More information about the Zope3-Checkins
mailing list