This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Repr class from repr module ignores maxtuple attribute
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: nnorwitz Nosy List: jasonjroberts, nnorwitz
Priority: normal Keywords:

Created on 2007-06-11 02:32 by jasonjroberts, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg32297 - (view) Author: Jason Roberts (jasonjroberts) Date: 2007-06-11 02:32
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.
msg32298 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2007-06-11 07:34
Thanks for the report Jason!

Committed revision 55887.
Committed revision 55888. (2.5)
History
Date User Action Args
2022-04-11 14:56:24adminsetgithub: 45078
2007-06-11 02:32:41jasonjrobertscreate