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: pprint wrongly formats set and frozenset subclasses
Type: behavior Stage: resolved
Components: Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: fdrake, pitrou, python-dev, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2013-10-01 14:55 by serhiy.storchaka, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pprint_set_subclass.patch serhiy.storchaka, 2013-10-01 14:55 review
pprint_set_subclass_2.patch serhiy.storchaka, 2013-10-01 17:05 review
Messages (3)
msg198788 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-10-01 14:55
Example:

>>> import pprint
>>> class S(set): pass
... 
>>> S('abc')
S({'a', 'b', 'c'})
>>> pprint.pprint(S('abc'))
S({'a', 'b', 'c'})
>>> pprint.pprint(S('abc'), width=1)
{'a',
 'b',
 'c'}

And same for frozenset.

Here is a patch which fixes this issue. With a patch:

>>> pprint.pprint(S('abc'), width=1)
S({'a',
   'b',
   'c'})
msg198793 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-10-01 17:05
Added an additional test to check the output layout for set/frozenset subclasses as Antoine suggested.
msg198820 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-10-02 08:45
New changeset fcd889046ee1 by Serhiy Storchaka in branch '2.7':
Issue #19137: The pprint module now correctly formats empty set and frozenset
http://hg.python.org/cpython/rev/fcd889046ee1

New changeset 65943dc15afc by Serhiy Storchaka in branch '3.3':
Issue #19137: The pprint module now correctly formats instances of set and
http://hg.python.org/cpython/rev/65943dc15afc

New changeset 2d21239a5205 by Serhiy Storchaka in branch 'default':
Issue #19137: The pprint module now correctly formats instances of set and
http://hg.python.org/cpython/rev/2d21239a5205
History
Date User Action Args
2022-04-11 14:57:51adminsetgithub: 63336
2013-10-02 08:57:14serhiy.storchakasetstatus: open -> closed
assignee: serhiy.storchaka
resolution: fixed
stage: patch review -> resolved
2013-10-02 08:45:44python-devsetnosy: + python-dev
messages: + msg198820
2013-10-01 17:05:43serhiy.storchakasetfiles: + pprint_set_subclass_2.patch

messages: + msg198793
2013-10-01 15:17:59serhiy.storchakasettitle: pprint wrongly format set and frozenset subclasses -> pprint wrongly formats set and frozenset subclasses
2013-10-01 14:55:31serhiy.storchakacreate