New submission from Danilo J. S. Bellini:

The pprint pretty printer in Python 3 sorts sets/frozensets only if their 
length don't fit in one single line/row for the given width, else it was just 
leaving repr(my_set_instance) alone, like:

>>> import string, pprint
>>> pprint.pprint(set(string.digits))
{'7', '5', '2', '4', '1', '9', '6', '3', '0', '8'}

That order is quite random in Python 3.2+. But on Python 2.6 and 2.7, the 
result is shown as:
set(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])

So for using pprint in doctests (or anything alike) with sets/frozensets, the 
pretty printer isn't as useful in Python 3 than it is in Python 2. The pprint 
tests for non-nested set/frozenset were only using some small ranges for 
testing. I've written a patch to solve that.

----------
components: Library (Lib)
files: pprint_small_set_sorted.patch
keywords: patch
messages: 270237
nosy: danilo.bellini
priority: normal
severity: normal
status: open
title: Pretty printing sorting for set and frozenset instances
type: behavior
versions: Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6
Added file: http://bugs.python.org/file43698/pprint_small_set_sorted.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27495>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to