[pypy-svn] r77740 - in pypy/branch/fast-forward/lib_pypy: . pypy_test

afa at codespeak.net afa at codespeak.net
Sat Oct 9 09:35:13 CEST 2010


Author: afa
Date: Sat Oct  9 09:35:10 2010
New Revision: 77740

Modified:
   pypy/branch/fast-forward/lib_pypy/_collections.py
   pypy/branch/fast-forward/lib_pypy/pypy_test/test_defaultdict.py
Log:
defaultdict accepts None for the __missing__ function


Modified: pypy/branch/fast-forward/lib_pypy/_collections.py
==============================================================================
--- pypy/branch/fast-forward/lib_pypy/_collections.py	(original)
+++ pypy/branch/fast-forward/lib_pypy/_collections.py	Sat Oct  9 09:35:10 2010
@@ -317,7 +317,7 @@
         self.default_factory = None
         if 'default_factory' in kwds:
             self.default_factory = kwds.pop('default_factory')
-        elif len(args) > 0 and callable(args[0]):
+        elif len(args) > 0 and (callable(args[0]) or args[0] is None):
             self.default_factory = args[0]
             args = args[1:]
         super(defaultdict, self).__init__(*args, **kwds)

Modified: pypy/branch/fast-forward/lib_pypy/pypy_test/test_defaultdict.py
==============================================================================
--- pypy/branch/fast-forward/lib_pypy/pypy_test/test_defaultdict.py	(original)
+++ pypy/branch/fast-forward/lib_pypy/pypy_test/test_defaultdict.py	Sat Oct  9 09:35:10 2010
@@ -48,6 +48,10 @@
         py.test.raises(KeyError, d2.__getitem__, 15)
         py.test.raises(TypeError, defaultdict, 1)
 
+    def test_constructor(self):
+        assert defaultdict(None) == {}
+        assert defaultdict(None, {1: 2}) == {1: 2}
+
     def test_missing(self):
         d1 = defaultdict()
         py.test.raises(KeyError, d1.__missing__, 42)



More information about the Pypy-commit mailing list