[Zope3-checkins] CVS: Zope3/src/zope/component/tests -
test_api.py:1.16
Jim Fulton
jim at zope.com
Sat Mar 6 10:39:16 EST 2004
Update of /cvs-repository/Zope3/src/zope/component/tests
In directory cvs.zope.org:/tmp/cvs-serv31748/src/zope/component/tests
Modified Files:
test_api.py
Log Message:
Added an optional argument to the interface __call__ method.
If the argument is provided, then the value provided will be
returned if adaptation can't be done. If a second argument isn't
provided, then a TypeError is raised if an adapter can't be computed.
The main motivation for this change is to provide queryAdapter-like
semantics, while also keeping PEP-246 adapt-like semantics (call
__conform__ before checking whether the object already provides the
interface).
So now, you can use:
adapter = IFoo(ob, None)
much as you might have used queryAdapter before (but with PEP 246
adapt semantics).
I generally avoid methods like this, that change their behavior
based on the number of arguments provided, however, I decided to
do it in this case to be more consistent with the PEP 246 adapt
method, and because this is __call__, rather than a "get" method.
I used a trick to avoid using a global marker. This trick uses nested
scopes to provide hidden "static" data for functions.
=== Zope3/src/zope/component/tests/test_api.py 1.15 => 1.16 ===
--- Zope3/src/zope/component/tests/test_api.py:1.15 Fri Mar 5 21:54:29 2004
+++ Zope3/src/zope/component/tests/test_api.py Sat Mar 6 10:38:45 2004
@@ -419,6 +419,7 @@
def testNotBrokenWhenNoService(self):
self.assertRaises(TypeError, I2, ob)
+ self.assertEquals(I2(ob, 42), 42)
More information about the Zope3-Checkins
mailing list