[Checkins] SVN: zc.sourcefactory/branches/0.3/ Allow subclasses of
the factories to have custom constructor signatures.
Christian Theune
ct at gocept.com
Tue Jun 10 11:04:31 EDT 2008
Log message for revision 87291:
Allow subclasses of the factories to have custom constructor signatures.
Changed:
U zc.sourcefactory/branches/0.3/CHANGES.txt
A zc.sourcefactory/branches/0.3/src/zc/sourcefactory/constructors.txt
U zc.sourcefactory/branches/0.3/src/zc/sourcefactory/factories.py
U zc.sourcefactory/branches/0.3/src/zc/sourcefactory/tests.py
-=-
Modified: zc.sourcefactory/branches/0.3/CHANGES.txt
===================================================================
--- zc.sourcefactory/branches/0.3/CHANGES.txt 2008-06-10 14:57:38 UTC (rev 87290)
+++ zc.sourcefactory/branches/0.3/CHANGES.txt 2008-06-10 15:04:30 UTC (rev 87291)
@@ -4,6 +4,9 @@
0.3.3 (unreleased)
------------------
+ - Fixed bug in __new__ of factories that would disallow subclasses to use
+ constructors that expect a different signature. (Thanks to Sebastian
+ Wehrmann for the patch.)
0.3.2 (2008-04-09)
------------------
Added: zc.sourcefactory/branches/0.3/src/zc/sourcefactory/constructors.txt
===================================================================
--- zc.sourcefactory/branches/0.3/src/zc/sourcefactory/constructors.txt (rev 0)
+++ zc.sourcefactory/branches/0.3/src/zc/sourcefactory/constructors.txt 2008-06-10 15:04:30 UTC (rev 87291)
@@ -0,0 +1,26 @@
+===================
+Custom constructors
+===================
+
+Source factories are intended to behave as natural as possible. A side-effect
+of using a custom factory method (__new__) on the base class is that
+sub-classes may have a hard time if their constructor (__init__) has a
+different signature.
+
+zc.sourcefactory takes extra measures to allow using a custom constructor with
+a different signature.
+
+>>> import zc.sourcefactory.basic
+
+>>> class Source(zc.sourcefactory.basic.BasicSourceFactory):
+...
+... def __init__(self, values):
+... super(Source, self).__init__()
+... self.values = values
+...
+... def getValues(self):
+... return self.values
+
+>>> source = Source([1, 2, 3])
+>>> list(source)
+[1, 2, 3]
Property changes on: zc.sourcefactory/branches/0.3/src/zc/sourcefactory/constructors.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: zc.sourcefactory/branches/0.3/src/zc/sourcefactory/factories.py
===================================================================
--- zc.sourcefactory/branches/0.3/src/zc/sourcefactory/factories.py 2008-06-10 14:57:38 UTC (rev 87290)
+++ zc.sourcefactory/branches/0.3/src/zc/sourcefactory/factories.py 2008-06-10 15:04:30 UTC (rev 87291)
@@ -32,10 +32,10 @@
zope.interface.implements(zc.sourcefactory.interfaces.ISourceFactory)
- 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 zc.sourcefactory.source.FactoredSource(factory)
Modified: zc.sourcefactory/branches/0.3/src/zc/sourcefactory/tests.py
===================================================================
--- zc.sourcefactory/branches/0.3/src/zc/sourcefactory/tests.py 2008-06-10 14:57:38 UTC (rev 87290)
+++ zc.sourcefactory/branches/0.3/src/zc/sourcefactory/tests.py 2008-06-10 15:04:30 UTC (rev 87291)
@@ -34,6 +34,7 @@
suite = unittest.TestSuite()
suite.addTest(doctest.DocFileSuite('README.txt'))
suite.addTest(doctest.DocFileSuite('mapping.txt'))
+ suite.addTest(doctest.DocFileSuite('constructors.txt'))
adapters = FunctionalDocFileSuite('adapters.txt')
adapters.layer = SourceFactoryLayer
suite.addTest(adapters)
More information about the Checkins
mailing list