[issue34798] pprint ignores the compact parameter for dicts

2018-09-25 Thread Nicolas Hug


Nicolas Hug  added the comment:

Thanks for the link,

But I don't see any justification for this behavior*? Why should lists be 
compacted but not dicts (even when explicitly asked)?

At the very least it should be made clear in the documentation that dicts are 
not compacted.

* Maybe there's more content in the patch reviews but I am unable to see them

--

___
Python tracker 
<https://bugs.python.org/issue34798>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34798] pprint ignores the compact parameter for dicts

2018-09-25 Thread Nicolas Hug


Nicolas Hug  added the comment:

Sorry:

[2] 
https://github.com/scikit-learn/scikit-learn/pull/11705/files#diff-f83e8d9362766b385472f1be7fed9482R96

--

___
Python tracker 
<https://bugs.python.org/issue34798>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34798] pprint ignores the compact parameter for dicts

2018-09-25 Thread Nicolas Hug


Nicolas Hug  added the comment:

Thank you for the feedback!

I'll try the python-ideas mail list. I posted a message on Python-list [1] a 
few weeks ago but it didn't get much traction.

I'm not sure about what the final solution could be (if any), but I had to hack 
pprint myself [2] for the scikit-learn project, and what I did was simply copy 
pasting _format_items into _format_dict_items, with some minimal changes.


[1] https://mail.python.org/pipermail/python-list/2018-September/737082.html
[2]

--

___
Python tracker 
<https://bugs.python.org/issue34798>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34798] pprint ignores the compact parameter for dicts

2018-09-25 Thread Nicolas Hug


Change by Nicolas Hug :


--
versions: +Python 3.8 -Python 3.7

___
Python tracker 
<https://bugs.python.org/issue34798>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34798] pprint ignores the compact parameter for dicts

2018-09-25 Thread Nicolas Hug


New submission from Nicolas Hug :

Dict representations that exceed the line width are printed with one line per 
key-value pair, ignoring the compact=True parameter:

>>> pprint.pprint({i: 0 for i in range(15)}, compact=True)
{0: 0,
 1: 0,
 2: 0,
 3: 0,
 4: 0,
 5: 0,
 6: 0,
 7: 0,
 8: 0,
 9: 0,
 10: 0,
 11: 0,
 12: 0,
 13: 0,
 14: 0}

Expected behavior:

>>> pprint.pprint({i: 0 for i in range(15)}, compact=True)
{0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, 10: 0, 11: 0,
 12: 0, 13: 0, 14: 0}

Note that lists are correctly compacted, and that dicts that don't exceed line 
width are printed on a single line, regardless on the compact parameter.

I could try to work on that if needed?

--
messages: 326358
nosy: Nicolas Hug
priority: normal
severity: normal
status: open
title: pprint ignores the compact parameter for dicts
type: behavior
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue34798>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com