tjreedy at udel.edu
Sun Sep 19 01:08:57 CEST 2010
On 9/17/2010 11:12 PM, Steven D'Aprano wrote:
> I was writing some tests for a mapping class I have made, and I decided
> to run those same tests over dict and UserDict. The built-in dict passed
> all the tests, but UserDict failed one:
You forgot to specify Python version ;-).
> class SimpleMappingTest(unittest.TestCase):
> type2test = UserDict.UserDict
In 3.x, collections.UserDict
> def test_iter(self):
> k, v = [0, 1, 2, 3], 'abcd'
> m = self.type2test(zip(k, v))
> it = iter(m)
> self.assert_(iter(it) is it)
> self.assertEquals(sorted(it), k) # This line fails.
Not in 3.x
k, v = [0, 1, 2, 3], 'abcd'
m = collections.UserDict(zip(k, v))
it = iter(m)
assert iter(it) is it
assert sorted(it) == k
> If I look at the source code for the UserDict module, I discover that
> there's a second mapping class, IterableUserDict,
Not any more. One of numerous 3.x cleanups made possible by dropping
obsessive back compatibility, which, as Peter explained, wan the reason
for the hack.
Terry Jan Reedy
More information about the Python-list