The Repr class from the repr module is supposed limit the number of tuple items dumped to the value of the maxtuple attribute. But it uses the value of the maxlist attribute instead:
def repr_tuple(self, x, level):
return self._repr_iterable(x, level, '(', ')', self.maxlist, ',')
As a result:
>>> import sys
>>> sys.version
'2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)]'
>>> import repr
>>> r = repr.Repr()
>>> r.maxtuple
6
>>> r.maxlist
6
>>> r.maxtuple = 3
>>> r.repr((1,2,3,4,5,6,7,8,9)) # Will print 6 items, not 3
'(1, 2, 3, 4, 5, 6, ...)'
>>> r.maxlist = 3
>>> r.repr((1,2,3,4,5,6,7,8,9)) # Now will print 3 items
'(1, 2, 3, ...)'
The implementation of repr_tuple should be changed to:
def repr_tuple(self, x, level):
return self._repr_iterable(x, level, '(', ')', self.maxtuple, ',')
Obviously this is not a major issue if nobody has noticed it by now. But it would be nice to correct the implementation to match the documentation.
In my scenario, I want to dump out all of the items of a tuple but only three items from any embedded list. Something like this:
>>> x = (......)
>>> import repr
>>> r = repr.Repr()
>>> r.maxtuple = 255
>>> r.maxlist = 3
>>> print r.repr(x)
But because maxlist controls both the dumping of lists and of tuples, I have to choose between only dumping a few items of the tuple and having small lists, or dumping all of the items in the tuple and having large lists.
|