[issue27495] Pretty printing sorting for set and frozenset instances

2016-07-13 Thread Danilo J. S. Bellini

Danilo J. S. Bellini added the comment:

Wouldn't a fix for all standard collections be a fix for Python 3.5+, therefore 
another issue? http://bugs.python.org/issue23870

This issue is about sets/frozensets Python 3.2+, and I'm pretty sure it's 
backwards compatible, as I don't think any code running on Python 3.2.6 would 
depend on pprint randomness (how could?). Also, a multiline pprint would sort 
(tested with Python 3.2.6):

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

I see no reason to see a fix to this inconsistent behavior (sorting on 
multiline, not sorting on single line) as an enhancement just for a new Python 
3.6 version. Besides being backwards compatible, the test_pprint was really 
verifying the order on set(range(n)) for small n, something that is already 
sorted by set.__repr__ but appears in test_pprint, which make me think it was 
intended as a pretty printer test, not as a set.__repr__ test.

--

___
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



[issue27495] Pretty printing sorting for set and frozenset instances

2016-07-12 Thread Danilo J. S. Bellini

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