[Checkins] SVN: zc.sourcefactory/trunk/ Fixed bug in __new__ of contexual factories that would disallow subclasses to use constructors that expect a different signature.
Michael Howitz
mh at gocept.com
Mon Dec 8 02:22:51 EST 2008
Log message for revision 93767:
Fixed bug in __new__ of contexual factories that would disallow subclasses to use constructors that expect a different signature.
Changed:
U zc.sourcefactory/trunk/CHANGES.txt
U zc.sourcefactory/trunk/src/zc/sourcefactory/constructors.txt
U zc.sourcefactory/trunk/src/zc/sourcefactory/factories.py
-=-
Modified: zc.sourcefactory/trunk/CHANGES.txt
===================================================================
--- zc.sourcefactory/trunk/CHANGES.txt 2008-12-08 07:22:06 UTC (rev 93766)
+++ zc.sourcefactory/trunk/CHANGES.txt 2008-12-08 07:22:51 UTC (rev 93767)
@@ -2,10 +2,14 @@
Changes
=======
-0.4.0 (unreleased)
+0.3.5 (unreleased)
==================
+ - Fixed bug in __new__ of contexual factories that would disallow
+ subclasses to use constructors that expect a different
+ signature. [icemac]
+
0.3.4 (2008-08-27)
==================
Modified: zc.sourcefactory/trunk/src/zc/sourcefactory/constructors.txt
===================================================================
--- zc.sourcefactory/trunk/src/zc/sourcefactory/constructors.txt 2008-12-08 07:22:06 UTC (rev 93766)
+++ zc.sourcefactory/trunk/src/zc/sourcefactory/constructors.txt 2008-12-08 07:22:51 UTC (rev 93767)
@@ -24,3 +24,23 @@
>>> source = Source([1, 2, 3])
>>> list(source)
[1, 2, 3]
+
+This is also true for contextual sources. The example is a bit silly
+but it shows that it works in principal:
+
+>>> import zc.sourcefactory.contextual
+>>> default_values = (4, 5, 6)
+>>> context_values = (6, 7, 8)
+>>> class ContextualSource(
+... zc.sourcefactory.contextual.BasicContextualSourceFactory):
+...
+... def __init__(self, defaults):
+... super(ContextualSource, self).__init__()
+... self.defaults = defaults
+...
+... def getValues(self, context):
+... return self.defaults + context
+
+>>> contextual_source = ContextualSource(default_values)(context_values)
+>>> list(contextual_source)
+[4, 5, 6, 6, 7, 8]
Modified: zc.sourcefactory/trunk/src/zc/sourcefactory/factories.py
===================================================================
--- zc.sourcefactory/trunk/src/zc/sourcefactory/factories.py 2008-12-08 07:22:06 UTC (rev 93766)
+++ zc.sourcefactory/trunk/src/zc/sourcefactory/factories.py 2008-12-08 07:22:51 UTC (rev 93767)
@@ -45,10 +45,10 @@
Implementors must provide an implementation for `getValues`.
"""
- def __new__(cls):
+ def __new__(cls, *args, **kw):
"""Create the factory object and return source."""
factory = object.__new__(cls)
- factory.__init__()
+ factory.__init__(*args, **kw)
return FactoredContextualSourceBinder(factory)
More information about the Checkins
mailing list