[issue505152] pprint should (optionally) use str

2022-04-10 Thread admin


Change by admin :


--
github: None -> 35939

___
Python tracker 

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



[issue489472] pprint produces unreadable dict output

2022-04-10 Thread admin


Change by admin :


--
github: None -> 35669

___
Python tracker 

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



[issue482003] dict display broken in pprint

2022-04-10 Thread admin


Change by admin :


--
github: None -> 35531

___
Python tracker 

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



[issue451538] L10n of pprint

2022-04-10 Thread admin


Change by admin :


--
github: None -> 34973

___
Python tracker 

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



[issue45559] pprint tests do not test pprint.pprint()

2022-02-18 Thread Eric V. Smith


Eric V. Smith  added the comment:

Sure, have a go at it!

Any testing of pprint.pprint() would be an improvement, but ideally all options 
should be tested.

It would probably be worthwhile to restructure the tests to run both pformat 
and pprint tests from the same logic, so that we only need to change one thing 
if new options are added. I haven't looked at the tests, so I'm not sure how 
much work this would be.

--

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



[issue45559] pprint tests do not test pprint.pprint()

2022-02-18 Thread Haz


Haz  added the comment:

Hi! Any chance I could take this on if it hasn't already been actioned please? 
I assume the scope is to test all the pprint options?

Thanks!

--
nosy: +hp310780

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



[issue45959] Teach pprint about dict views

2022-01-17 Thread Éric Araujo

Éric Araujo  added the comment:

The PR looks good!  When the last comments are resolved, unless there is 
activity from other core devs, I will merge it.

--
nosy: +eric.araujo

___
Python tracker 

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



[issue42259] pprint: infinite recursion for saferepr() when using nested objects, but str() works

2022-01-03 Thread Irit Katriel


Irit Katriel  added the comment:

The documentation change in the PR clarifies the current state of things. 

@serhiy.storchaka - do you have a view on whether we should aim for an actual 
fix, or just document and close?

--

___
Python tracker 

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



[issue42259] pprint: infinite recursion for saferepr() when using nested objects, but str() works

2021-12-28 Thread Irit Katriel


Change by Irit Katriel :


--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue42259] pprint: infinite recursion for saferepr() when using nested objects, but str() works

2021-12-25 Thread Andrei Kulakov


Andrei Kulakov  added the comment:

The recursion protection in `saferepr` applies when two conditions are met: 

- the structure is subclassed from list, tuple or dict
- __repr__ is not overriden

In this case neither condition is met.

However, the recursion is caused by the `__repr__` so when it's removed, 
recursion doesn't happen (but not due to recursion protection).

Btw also note that recursive path must be continuous for recursion detection to 
apply, e.g. if it's list[cust_obj[list[cust_obj...]]], detection also won't 
work.

I don't think we can fix this in code in a straightforward way, because  we 
want to avoid recursively calling saferepr in case __repr__ does not recurse.

In other words, if we knew __repr__ DOES recurse, we could call saferepr 
recursively and apply recursion detection without any problems, but __repr__ 
might intentionally say something like "", and then 
recursively calling saferepr would be undesirable.

So unfortunately we lose the recursion detection because of that.

One possible option would be to add an optional param like *force_recursion*, 
to recurse with detection even on overridden *__repr__*. I'm not sure it's 
worth it. But that's something users can consider: subclass PrettyPrinter and 
override saferepr() and either remove the checks for __repr__ override or add a 
param to do just that.

Current docs really make it sound like any recursion that shows up in repr() 
will be protected; it's really much more limited than that. Adding PR to 
clarify the limitations.

--
versions: +Python 3.11 -Python 3.8

___
Python tracker 

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



[issue42259] pprint: infinite recursion for saferepr() when using nested objects, but str() works

2021-12-25 Thread Andrei Kulakov


Change by Andrei Kulakov :


--
keywords: +patch
nosy: +andrei.avk
nosy_count: 2.0 -> 3.0
pull_requests: +28477
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/30256

___
Python tracker 

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



[issue45959] Teach pprint about dict views

2021-12-16 Thread Daniel Diniz


Daniel Diniz  added the comment:

I have tried to add this. The PR adds:
- PrettyPrinter._pprint_dict_view to handle dict_keys and dict_values (sorted 
with _safe_key).
= PrettyPrinter._pprint_dict_items_view to handle dict_items (sorted using 
_safe_tuple).
- Tests.

Would a NEWS entry or other form of documentation be necessary?

--

___
Python tracker 

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



[issue45959] Teach pprint about dict views

2021-12-16 Thread Daniel Diniz


Change by Daniel Diniz :


--
keywords: +patch
nosy: +ajaksu2
nosy_count: 4.0 -> 5.0
pull_requests: +28355
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/30135

___
Python tracker 

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



[issue45959] Teach pprint about dict views

2021-12-15 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

More accurate to say that it aspires to print in a single line ONLY if the 
content fits in the specified width.  Otherwise, it prints vertically with 
appropriate indentation.  Indeed, that is the entire purpose of the module; 
otherwise, we would just use print() which always writes one line.

--

___
Python tracker 

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



[issue45959] Teach pprint about dict views

2021-12-14 Thread Joshua Insel


Joshua Insel  added the comment:

According to the documentation for pprint, it is supposed to print objects on a 
single line if possible. See the second paragraph here: 
https://docs.python.org/3/library/pprint.html

--
nosy: +joshinsel

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



[issue45959] Teach pprint about dict views

2021-12-13 Thread David Peled


Change by David Peled :


--
nosy: +david-peled

___
Python tracker 

___
___
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

2021-12-11 Thread Irit Katriel


Irit Katriel  added the comment:

Don't discuss on a closed issue. Create a new one if there is still a problem.

--

___
Python tracker 

___
___
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

2021-12-11 Thread Matt Bogosian


Matt Bogosian  added the comment:

Please consider highlighting that dicts are not included in the documentation. 
While *technically* true, this ...

> compact impacts the way that long sequences (lists, tuples, sets, etc) are 
> formatted. If compact is false (the default) then each item of a sequence 
> will be formatted on a separate line. If compact is true, as many items as 
> will fit within the width will be formatted on each output line.

... has several problems.

First, sequence is a term of art that also has a common meaning. This creates a 
potential ambiguity in the understanding of the reader. Resolving that 
ambiguity in this context requires that readers have already internalized that 
dicts are not Python sequences. Those new to Python may not understand the (to 
them, subtle) differences between Python's iterables and sequences. Second, the 
"etc" only expands that ambiguity and invites confusion. Third, the term 
"items" is strongly associated with dicts and is used several times throughout 
the paragraph.

This ...

> According to https://docs.python.org/3/library/pprint.html compact impacts 
> the way that sequences are displayed, and a dict is not a sequence.

... is unhelpfully pedantic, and ignorant of the needs of the newcomer (a key 
demographic of documentation). Documentation is a core product surface with a 
diverse audience. Rather than focus on technical correctness, documentation 
authors should focus on accessibility. Redundancy is a feature, not a bug. You 
can't predict how your reader got to that slice of the documentation. Imagine 
this as an opportunity to educate or reinforce concepts for readers, not as an 
opportunity to argue from a position of technical superiority.

The fact that there are now four developers who have taken their time to file 
patches, bugs, and comments is pretty strong signal that confusion exists among 
the audience and that the documentation is insufficient.

--
nosy: +posita

___
Python tracker 

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



[issue45959] Teach pprint about dict views

2021-12-02 Thread Alex Waygood


Change by Alex Waygood :


--
nosy: +AlexWaygood

___
Python tracker 

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



[issue45959] Teach pprint about dict views

2021-12-01 Thread Raymond Hettinger


New submission from Raymond Hettinger :

The pprint() code has a number of type or protocol specific handlers but 
doesn't have one for dict views.  So, we don't get pretty printing for the 
key(), values(), and items():

d = {i:i for i in range(100)}
pprint(d) # This is handled correctly
pprint(d.keys())  # Printed on one line
pprint(d.values())# Printed on one line
pprint(d.items()) # Printed on one line

--
components: Library (Lib)
keywords: easy
messages: 407513
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Teach pprint about dict views
type: enhancement
versions: Python 3.11

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



[issue45611] pprint - low width overrides depth folding

2021-10-26 Thread Ian Currie


New submission from Ian Currie :

Reproducible example:

>>> from pprint import pprint
>>> data = [["aa"],[2],[3],[4],[5]]
>>> pprint(data)
[["aaaaaa"], [2], [3], [4], [5]]

>>> pprint(data, depth=1)
[[...], [...], [...], [...], [...]]

>>> pprint(data, depth=1, width=7)
[[...],
 [...],
 [...],
 [...],
 [...]]

>>> pprint(data, depth=1, width=6)
[['aa'],
 [2],
 [3],
 [4],
 [5]]

The depth "folds" everything deeper than 1 level. Then if you lower the width 
of the output enough, what was once on one line, will now be split by newlines.

The bug is, if you lower the width below seven characters. Which is the length 
of `[[...],`  It seems to override the `depth` parameter and print the 
everything with no folding. This is true of deeply nested structures too.

Expected behavior: for the folding `...` to remain.

Why put the width so low?

I came across this because of the behavior of `compact`:

By default, if a data structure can fit on one line, it will be displayed on 
one line. `compact` only affects sequences that are longer than the given width.

**There is no way to force compact as False for short items**, so as to make 
sure all items, even short ones, appear on their own line.

[1,2,3] - will always appear on its own line, there is no way to make it appear 
like:

[1,
 2,
 3]

The only way is by setting a very low width.

--
components: Library (Lib)
messages: 405027
nosy: iansedano
priority: normal
severity: normal
status: open
title: pprint - low width overrides depth folding
type: behavior
versions: Python 3.10

___
Python tracker 
<https://bugs.python.org/issue45611>
___
___
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

2021-10-25 Thread Ian


Ian  added the comment:

I came across this and was confused by it too. I also don't understand the 
justification with not having dicts to be affected by the `compact` parameter.

If the "compact form" is having separate entries or elements on one line, 
instead of having each element separated by a new line, then it seems like 
inconsistent behavior.

**If a dict is short enough, it will appear in "compact form", just like a 
list.**

If a dict is too long for the width, then each item will appear in "expanded 
form", also like a list.
However, the actual compact parameter only affects sequence items. Why is this?

There is no reason given in #19132. It does mention a review, but it doesn't 
seem to be available, or I don't know how to get to it, to understand the 
reason for that decision.

--
nosy: +iansedano

___
Python tracker 

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



[issue45559] pprint tests do not test pprint.pprint()

2021-10-21 Thread Eric V. Smith


Change by Eric V. Smith :


--
title: pprint module does not test pprint.pprint() -> pprint tests do not test 
pprint.pprint()

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



[issue45557] pprint -> underscore_numbers argument not working

2021-10-21 Thread Eric V. Smith


Change by Eric V. Smith :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
versions: +Python 3.10, Python 3.11

___
Python tracker 

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



[issue45557] pprint -> underscore_numbers argument not working

2021-10-21 Thread miss-islington


miss-islington  added the comment:


New changeset 6b75ad5fd47e5b34a04197927f748d0391898de7 by Miss Islington (bot) 
in branch '3.10':
bpo-45557: Fix underscore_numbers in pprint.pprint(). (GH-29129)
https://github.com/python/cpython/commit/6b75ad5fd47e5b34a04197927f748d0391898de7


--

___
Python tracker 

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



[issue45557] pprint -> underscore_numbers argument not working

2021-10-21 Thread Eric V. Smith


Eric V. Smith  added the comment:


New changeset 087f089e5e04d5b132ffbff0576667d591f13219 by Eric V. Smith in 
branch 'main':
bpo-45557: Fix underscore_numbers in pprint.pprint(). (GH-29129)
https://github.com/python/cpython/commit/087f089e5e04d5b132ffbff0576667d591f13219


--

___
Python tracker 

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



[issue45557] pprint -> underscore_numbers argument not working

2021-10-21 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 2.0 -> 3.0
pull_requests: +27409
pull_request: https://github.com/python/cpython/pull/29133

___
Python tracker 

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



[issue45559] pprint module does not test pprint.pprint()

2021-10-21 Thread Eric V. Smith


New submission from Eric V. Smith :

For example, see issue 45557, where pprint.pformat(underscore_numbers=True) 
worked, but pprint.pprint(underscore_numbers=True) did not.

Testing of pprint.pprint() should be added.

--
components: Library (Lib)
messages: 404647
nosy: eric.smith
priority: normal
severity: normal
status: open
title: pprint module does not test pprint.pprint()
type: behavior
versions: Python 3.10, Python 3.11, Python 3.9

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



[issue45557] pprint -> underscore_numbers argument not working

2021-10-21 Thread Eric V. Smith


Change by Eric V. Smith :


--
keywords: +patch
pull_requests: +27405
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/29129

___
Python tracker 

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



[issue45557] pprint -> underscore_numbers argument not working

2021-10-21 Thread Eric V. Smith


Eric V. Smith  added the comment:

It's a bug in pprint.py. PR to follow shortly.

--

___
Python tracker 

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



[issue45557] pprint -> underscore_numbers argument not working

2021-10-21 Thread Eric V. Smith


Eric V. Smith  added the comment:

Please do not post screen shots. They don't work for people with vision 
impairments, and we can't copy and past from them, so it makes it harder for us 
to help you.

It looks like it works with pformat, and not pprint:

>>> pprint.pformat(1, underscore_numbers=True)
'10_000'
>>> pprint.pprint(1, underscore_numbers=True)
1

--
nosy: +eric.smith

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



[issue45557] pprint -> underscore_numbers argument not working

2021-10-21 Thread Jean-Philippe VINCENT


Change by Jean-Philippe VINCENT :


--
title: Issue 42914 -> pprint -> underscore_numbers argument not working

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



[issue42914] pprint numbers with underscore

2021-10-09 Thread Stéphane Blondon

Stéphane Blondon  added the comment:

Ok, I will not send a PR to change the current behavior until python4 (in case 
it exists one day).

--

___
Python tracker 

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



[issue42914] pprint numbers with underscore

2021-10-05 Thread Eric V. Smith


Eric V. Smith  added the comment:

The safest thing to do is never make it the default. It would always be an 
opt-in behavior.

--

___
Python tracker 

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



[issue42914] pprint numbers with underscore

2021-10-05 Thread Stéphane Blondon

Stéphane Blondon  added the comment:

Python 3.10 has now been released with the underscore_numbers parameter.
I wonder which release could enable the parameter by default (so it would break 
the previous behavior):
 - the next release (3.11) is probably too short.
 - the safest strategy is to wait until 3.9 will be end-of-life (2025-10 
according to [1]). In such case, it could be integrated in 3.14.

Could it be accepted before (like 3.12 or 3.13)?

If there is no reply, I will create a new issue and PR for 3.14 inclusion ( = 
safest strategy).


1: https://devguide.python.org/#status-of-python-branches

--

___
Python tracker 

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



[issue41546] pprint() gives exception when ran from pythonw

2021-07-19 Thread Irit Katriel


Change by Irit Katriel :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue41546] pprint() gives exception when ran from pythonw

2021-07-19 Thread Irit Katriel


Irit Katriel  added the comment:


New changeset aab1899c9d79083c1ff31d974ed8b562d3ca3b5d by Irit Katriel in 
branch 'main':
bpo-41546: make pprint (like print) not write to stdout when it is None 
(GH-26810)
https://github.com/python/cpython/commit/aab1899c9d79083c1ff31d974ed8b562d3ca3b5d


--

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



[issue44580] pprint does not work for typing.Mapping

2021-07-07 Thread Hayden Clark


New submission from Hayden Clark :

If you make a user-defined type that inherits from typing.Mapping (which is an 
alias for collections.abc.Mapping), pprint does not dump the contents, it just 
treats it as an unknown class.
Examining the code, it is explicitly checking for "dict" type, even though it 
is only reading the data.

Here is a reproduction:
from typing import Mapping
from pprint import pprint


class MyMap(Mapping):
def __init__(self, **kwargs) -> None:
self.data = {
k:v for k, v in kwargs.items()
}

def __getitem__(self, k):
return self.data.get(k)

def __len__(self):
return self.data.__len__()

def __iter__(self):
return self.data.__iter__()


info = MyMap(
foo="bar",
baz=MyMap(bar="foo")
)

pprint(info)

--

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



[issue44580] pprint does not work for typing.Mapping

2021-07-07 Thread Hayden Clark


Change by Hayden Clark :


--
components: Library (Lib)
nosy: hclark
priority: normal
severity: normal
status: open
title: pprint does not work for typing.Mapping
type: behavior
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue44580>
___
___
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

2021-07-02 Thread Irit Katriel


Change by Irit Katriel :


--
versions:  -Python 3.9

___
Python tracker 

___
___
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

2021-07-02 Thread Irit Katriel


Change by Irit Katriel :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
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

2021-07-02 Thread Irit Katriel

Irit Katriel  added the comment:


New changeset 42c26282a123d14591e1aa31107e566b302a19ac by Miss Islington (bot) 
in branch '3.10':
bpo-34798: [doc] clearer presentation of pprint.PrettyPrinter constru… 
(GH-26967) (GH-26990)
https://github.com/python/cpython/commit/42c26282a123d14591e1aa31107e566b302a19ac


--

___
Python tracker 

___
___
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

2021-07-02 Thread Irit Katriel

Irit Katriel  added the comment:


New changeset 943e77d42d3f84b581f32c05f1fc8c05366b8ed3 by Irit Katriel in 
branch 'main':
bpo-34798: [doc] clearer presentation of pprint.PrettyPrinter constru… 
(GH-26967)
https://github.com/python/cpython/commit/943e77d42d3f84b581f32c05f1fc8c05366b8ed3


--

___
Python tracker 

___
___
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

2021-07-02 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 5.0 -> 6.0
pull_requests: +25552
pull_request: https://github.com/python/cpython/pull/26990

___
Python tracker 

___
___
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

2021-06-30 Thread Irit Katriel


Irit Katriel  added the comment:

I made PR26967 to break up the paragraph about the constructor params so that 
it's easier to read, and also added emphasis around the "sequence" point.

--
versions: +Python 3.10, Python 3.11, Python 3.9 -Python 3.8

___
Python tracker 

___
___
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

2021-06-30 Thread Irit Katriel


Change by Irit Katriel :


--
keywords: +patch
pull_requests: +25531
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26967

___
Python tracker 

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



[issue41546] pprint() gives exception when ran from pythonw

2021-06-20 Thread Irit Katriel


Change by Irit Katriel :


--
versions: +Python 3.11 -Python 3.10

___
Python tracker 

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



[issue41546] pprint() gives exception when ran from pythonw

2021-06-20 Thread Irit Katriel


Change by Irit Katriel :


--
keywords: +patch
nosy: +iritkatriel
nosy_count: 9.0 -> 10.0
pull_requests: +25392
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26810

___
Python tracker 

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



[issue42914] pprint numbers with underscore

2021-06-02 Thread miss-islington


miss-islington  added the comment:


New changeset 41317801a95c758c3fc04c4fb332ac453c9e3ad3 by Miss Islington (bot) 
in branch '3.10':
Add bpo-42914 to What's New (GH-25124)
https://github.com/python/cpython/commit/41317801a95c758c3fc04c4fb332ac453c9e3ad3


--

___
Python tracker 

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



[issue42914] pprint numbers with underscore

2021-06-02 Thread miss-islington


miss-islington  added the comment:


New changeset 4846ea95d1a121df5e8081e2a290f63d1419cad8 by Wm. Keith van der 
Meulen in branch 'main':
Add bpo-42914 to What's New (GH-25124)
https://github.com/python/cpython/commit/4846ea95d1a121df5e8081e2a290f63d1419cad8


--
nosy: +miss-islington

___
Python tracker 

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



[issue42914] pprint numbers with underscore

2021-06-02 Thread miss-islington


Change by miss-islington :


--
pull_requests: +25105
pull_request: https://github.com/python/cpython/pull/26509

___
Python tracker 

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



[issue43080] pprint for dataclass instances

2021-04-13 Thread Eric V. Smith


Eric V. Smith  added the comment:

Thanks for all of the work, LewisGaul.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue43080] pprint for dataclass instances

2021-04-13 Thread Eric V. Smith


Eric V. Smith  added the comment:


New changeset 11159d2c9d6616497ef4cc62953a5c3cc8454afb by Lewis Gaul in branch 
'master':
bpo-43080: pprint for dataclass instances (GH-24389)
https://github.com/python/cpython/commit/11159d2c9d6616497ef4cc62953a5c3cc8454afb


--

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



[issue42914] pprint numbers with underscore

2021-03-31 Thread Wm. Keith van der Meulen


Change by Wm. Keith van der Meulen :


--
nosy: +wkeithvan
nosy_count: 7.0 -> 8.0
pull_requests: +23872
pull_request: https://github.com/python/cpython/pull/25124

___
Python tracker 

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



[issue42914] pprint numbers with underscore

2021-03-24 Thread Gregory P. Smith

Gregory P. Smith  added the comment:

Thanks for the contribution Stéphane!

I agree that this would be a nice default.  We're just being conservative in 
the pace of default behavior changes.  Changing the default could be considered 
in the future after a few releases with this parameter have shipped.

--
resolution:  -> fixed
stage: patch review -> commit review
status: open -> closed

___
Python tracker 

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



[issue42914] pprint numbers with underscore

2021-03-24 Thread Gregory P. Smith


Gregory P. Smith  added the comment:


New changeset 3ba3d513b1e3c63d09cb798b982a9e6c369cea4c by sblondon in branch 
'master':
bpo-42914: add a pprint underscore_numbers option (GH-24864)
https://github.com/python/cpython/commit/3ba3d513b1e3c63d09cb798b982a9e6c369cea4c


--

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



[issue42914] pprint numbers with underscore

2021-03-22 Thread Stéphane Blondon

Stéphane Blondon  added the comment:

I changed the default to be backward compatible (so underscore_numbers=False).

I think it would be better with underscore_numbers enabled by default but I 
understand the need for stability. Perhaps such break could be done in the 
future (in version 3.12 or v.4)?

--

___
Python tracker 

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



[issue42914] pprint numbers with underscore

2021-03-20 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

I don't think underscores can be on by default.  It needs to be opt-in to be 
backwards compatible.

--

___
Python tracker 

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



[issue42914] pprint numbers with underscore

2021-03-20 Thread Gregory P. Smith


Change by Gregory P. Smith :


--
nosy: +gregory.p.smith

___
Python tracker 

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



[issue43080] pprint for dataclass instances

2021-03-20 Thread Gregory P. Smith


Gregory P. Smith  added the comment:

+0.5 I lean towards just accepting this under the conditions Eric describes 
given that dataclass is a stdlib concept and nobody is likely to claim that 
such output from pprint is a bad thing.

The larger "some form of protocol for pprint to work on all sorts of other 
things" issue (regardless of how) remains a long term wish list item that'll 
probably wind up in PEP land if someone wants to take it on.

--
nosy: +gregory.p.smith

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



[issue29996] Use terminal width by default in pprint

2021-03-20 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Closing then. I'll just add my implementation in my .pythonrc.py.

--
resolution:  -> rejected
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue29996] Use terminal width by default in pprint

2021-03-20 Thread Eryk Sun


Change by Eryk Sun :


--
versions: +Python 3.10, Python 3.8, Python 3.9 -Python 3.7

___
Python tracker 

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



[issue29996] Use terminal width by default in pprint

2021-03-20 Thread Eryk Sun


Change by Eryk Sun :


--
Removed message: https://bugs.python.org/msg291198

___
Python tracker 

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



[issue43080] pprint for dataclass instances

2021-03-16 Thread Lewis Gaul


Lewis Gaul  added the comment:

> FWIW, we've not had a feature request for this ever, nor has there been a 
> request for pprint to support attrs, nor any other hand-rolled class that 
> implements methods similar to those generated by dataclasses.

I wouldn't expect core Python to support a 3rd party lib like attrs, but I fail 
to see what's so different between dataclasses, SimpleNamespace and namedtuple 
- all of these may be used for storing/modelling [nested] data, which then may 
be printed.

> AFAICT, this tracker issue wasn't motivated by a known use case; rather, it 
> was "my PR was accepted for SimpleNamespace and thought dataclasses could be 
> the next."

This issue is entirely motivated by a real-world example - I'm currently 
maintaining a private fork of the pprint module with support for dataclasses 
added. I'm assuming the reason this hasn't come up before is that dataclasses 
are relatively new (and plenty of users will still be on older versions of 
Python).

I was not the author of the issue that added support for SimpleNamespace, I 
just saw it and used it as an example of precedent.

> At some point, we need a modern redesign alternative to pprint.

I'm on board with this, but as Eric said there aren't currently any signs of 
this being worked on. In absence of a redesign, dataclass support seems like a 
natural extension to me.

--

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



[issue43080] pprint for dataclass instances

2021-03-15 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

FWIW, we've not had a feature request for this ever, nor has there been a 
request for pprint to support attrs, nor any other hand-rolled class that 
implements methods similar to those generated by dataclasses.  AFAICT, this 
tracker issue wasn't motivated by a known use case; rather, it was "my PR was 
accepted for SimpleNamespace and thought dataclasses could be the next."

In the absence of known use cases and user requests, I think we should let it 
be.  Put me down for a -0.

--

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



[issue43080] pprint for dataclass instances

2021-03-15 Thread Eric V. Smith


Eric V. Smith  added the comment:

I'm leaning toward accepting this on the condition that it only be invoked for 
dataclasses where __repr__ was the version generated by @dataclass. And also 
that it use the same fields that the generated __repr__ would use (basically 
skipping repr=False fields). Under those conditions, I don't see the harm.

The reason I'm leaning toward acceptance is that we've talked about a better 
pprint for ages, and yet there's no activity that I can tell toward developing 
a replacement in the stdlib. pprint was a motivating example for PEP 443 
(singledispatch), and that was accepted 8 years ago. I don't think we should 
have to wait forever to get better pprint for dataclasses.

But I'm still not 100% decided, and I can be reasoned with!

--

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



[issue42914] pprint numbers with underscore

2021-03-14 Thread Stéphane Blondon

Stéphane Blondon  added the comment:

Thank you Felipe for the news! :)
I have committed a PR about this issue.

Two remarks:
- I changed the proposed implementation from 'format(integer, '_d')' to 
'{:_d}.format(integer)' because the first way raised an exception. (The 
`format` function was not defined.)
- I thought about adding the same behavior for float too but I didn't add it 
because the '_f' type uses a precision of 6 digits after the decimal point for 
float. So it's possible some precision would be lost with the pprint() call. It 
could mislead users more than helping them with the readability of the '_'. A 
precision value can be added but I'm not sure it's a good idea. based on [1]

As requested, there is a new parameter to disable this new behavior 
('underscore_numbers').


1: 
https://docs.python.org/3/library/string.html#format-specification-mini-language

--

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



[issue42914] pprint numbers with underscore

2021-03-14 Thread Stéphane Blondon

Change by Stéphane Blondon :


--
keywords: +patch
pull_requests: +23624
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/24864

___
Python tracker 

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



[issue42914] pprint numbers with underscore

2021-03-09 Thread Felipe

Felipe  added the comment:

All yours! I'm tied up so won't be able to submit the PR

On Thu, 25 Feb 2021 at 10:12, Stéphane Blondon 
wrote:

>
> Stéphane Blondon  added the comment:
>
> I add the same idea but later than you, so I'm interested by such feature.
>
> Felipe: do you want to add a pull request to this issue (with Serhiy
> Storchaka implementation because it's the simplest one)?
>
> If not, I plan to write it.
> I will write it too if there is no reply in one month.
>
> --
> nosy: +sblondon
>
> ___
> Python tracker 
> 
> ___
>

--

___
Python tracker 

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



[issue42914] pprint numbers with underscore

2021-02-25 Thread Mark Dickinson


Change by Mark Dickinson :


--
nosy: +mark.dickinson

___
Python tracker 

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



[issue42914] pprint numbers with underscore

2021-02-25 Thread Stéphane Blondon

Stéphane Blondon  added the comment:

I add the same idea but later than you, so I'm interested by such feature.

Felipe: do you want to add a pull request to this issue (with Serhiy Storchaka 
implementation because it's the simplest one)?

If not, I plan to write it.
I will write it too if there is no reply in one month.

--
nosy: +sblondon

___
Python tracker 

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



[issue43080] pprint for dataclass instances

2021-01-31 Thread Eric V. Smith


Eric V. Smith  added the comment:

I agree that we need a better pprint. I think it would be easier to create 
something new rather than try and morph the existing pprint, but maybe I lack 
enough imagination. I'd prefer to use functools.singledispatch instead of a 
__pprint__ method, but it doesn't really make a lot of difference. PEP 443 
(singledispatch) does use pprint as a motivating example.

I tend to agree with Raymond that we don't want to guess what a dataclass class 
intends as its usage. After all, we deliberately made it easy to add a custom 
__repr__ (one not generated by dataclasses.dataclass).

--

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



[issue43080] pprint for dataclass instances

2021-01-31 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

At some point, we need a modern redesign alternative to pprint.  It could have 
its own __pprint__ method to communicate how it wants to be pretty printed.

Until then, I think the existing pprint module should only grow custom support 
for classes that have a mostly consistent structure and usage pattern.  
SimpleNamespace, for example, made sense for a custom pprint handler because it 
is so dict like and is almost never customized.

IMO, dataclasses are a bridge too far.  Having pprint() guess what a dataclass 
intends is not far from try to guess what an arbitrary class intends.  This is 
skating on thin ice.

--

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



[issue43080] pprint for dataclass instances

2021-01-31 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Good idea Eric, it should work.

But it can make the code of pprint potentially less flexible. Currently it uses 
a mapping which maps __repr__ to corresponding pprint implementation. Only 
exception is for dicts, for historical reasons. It potentially can allow to 
make pprint more general and support arbitrary types by registering some 
handlers. Since there is no standard implementation of __repr__ for namedtuples 
and dataclasses we cannot use them as keys, and need to hardcode checks for 
namedtuple and dataclass (and any other generated classes).

It is a minor objection. Perhaps practicality should beat purity in this case.

--

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



[issue43080] pprint for dataclass instances

2021-01-31 Thread Lewis Gaul


Lewis Gaul  added the comment:

@Serhiy - Yes, I noted that problem in the PR. Thanks for pointing me to that 
issue, I agree it would be good to make pprint properly extensible (my current 
solution is to maintain a fork of the pprint module with dataclass support 
added).

Eric's suggestion would work, I wasn't sure if it would be considered an 'ok' 
thing to do, but if so then could be an easy enough way to support dataclasses 
(and namedtuples potentially)?

--

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



[issue43080] pprint for dataclass instances

2021-01-31 Thread Eric V. Smith


Eric V. Smith  added the comment:

Adding an attribute on the __repr__ (and other methods?) signifying that they 
were generated would let us distinguish them.

Say, checking getattr(__repr__, '__is_generated__', False), or similar.

--

___
Python tracker 

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



[issue43080] pprint for dataclass instances

2021-01-31 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

For all other classes we check that there is no user defined __repr__. But it 
is difficult to check this for dataclass or namedtuple because there is no base 
class for dataclasses or namedtuples which provides standard __repr__ 
implementation. All __repr__ for dataclasses and namedtuples are generated.

See issue7434.

--

___
Python tracker 

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



[issue43080] pprint for dataclass instances

2021-01-31 Thread Lewis Gaul


Lewis Gaul  added the comment:

> a dataclass can do anything a regular class can do

Agreed, but isn't that also true of any subclasses of currently supported 
types? In particular 'UserDict', 'UserList' and 'UserString', which all have 
explicit support in pprint and are intended for "easier subclassing" according 
to the docs.

I'm also not sure why it would be a reason for not giving it pprint handling 
(in the case where there's no user-defined __repr__). Is there any harm in 
doing so? 

I'd consider dataclasses one of the primary choices for storing data in modern 
Python (e.g. for converting to/from JSON/YAML), and may well be used for 
storing nested data, which can be very hard to read without some mechanism for 
pretty-printing.

Indeed, the dataclasses.asdict() function recurses into dataclass fields. This 
gives the option of pprint(dataclasses.asdict(my_dataclass)), but at the cost 
of losing the class names and any custom reprs.

--

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



[issue43080] pprint for dataclass instances

2021-01-31 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Since a dataclass can do anything a regular class can do, it is probably too 
general to have a special case for pprint.

--
assignee:  -> eric.smith
nosy: +eric.smith

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



[issue43080] pprint for dataclass instances

2021-01-30 Thread Lewis Gaul


Change by Lewis Gaul :


--
keywords: +patch
pull_requests: +23204
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/24389

___
Python tracker 

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



[issue43080] pprint for dataclass instances

2021-01-30 Thread Lewis Gaul


New submission from Lewis Gaul :

Currently the pprint module does not have support for dataclasses. I have 
implemented support for this and will link the PR once I have the issue number!

See also issue37376 for SimpleNamespace support.

--
components: Library (Lib)
messages: 386002
nosy: LewisGaul, eric.snow, rhettinger, serhiy.storchaka
priority: normal
severity: normal
status: open
title: pprint for dataclass instances
type: enhancement
versions: Python 3.10

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



[issue42914] pprint numbers with underscore

2021-01-13 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

>>> format(10**9, '_d')
'1_000_000_000'

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue42914] pprint numbers with underscore

2021-01-13 Thread Eric V. Smith


Eric V. Smith  added the comment:

+1 also. I agree with Raymond it should be optional.

--
nosy: +eric.smith

___
Python tracker 

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



[issue42914] pprint numbers with underscore

2021-01-12 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

> It would be nice if pprint learned to insert underscores in long numbers

+1 but I would make this optional.


> Here is an implementation of the safe repr for numbers if helpful

I suggest using the existing string formatting tools as a foundation

>>> format(10**9, ',d').replace(',', '_')
'1_000_000_000'

--
nosy: +rhettinger

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



[issue42914] pprint numbers with underscore

2021-01-12 Thread Felipe


Felipe  added the comment:

Here is an implementation of the safe repr for numbers if helpful:

```
def safe_repr_int(object):
sign = ''
if object < 0:
sign = '-'
object  = -object
r = repr(object)
if len(r) <= 4:
return sign + r
parts = [sign]
left = len(r) % 3
if left:
parts.append(r[0:left])
parts.append('_')
r = r[left:]
parts.append(r[0:3])
for i in range(3, len(r), 3):
parts.append('_')
parts.append(r[i:i + 3])
return ''.join(parts)
```

--

___
Python tracker 

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



[issue42914] pprint numbers with underscore

2021-01-12 Thread Felipe


New submission from Felipe :

It would be nice if pprint learned to insert underscores in long numbers

Current behavior:

>>> pprint.pprint(int(1e9))
10

Desired behavior

>>> pprint.pprint(int(1e9))
1_000_000_000

Wikipedia tells me that "groups of 3" is the international standard to be 
followed here [1][2]

[1] https://en.wikipedia.org/wiki/ISO_31-0#Numbers
[2] https://en.wikipedia.org/wiki/Decimal_separator#Digit_grouping

--
components: Library (Lib)
messages: 384982
nosy: fov
priority: normal
severity: normal
status: open
title: pprint numbers with underscore
type: enhancement
versions: Python 3.10

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



[issue42852] pprint fails in transformming non-breaking space

2021-01-07 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
resolution: fixed -> not a bug

___
Python tracker 

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



[issue42852] pprint fails in transformming non-breaking space

2021-01-07 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
resolution:  -> fixed
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



[issue42852] pprint fails in transformming non-breaking space

2021-01-07 Thread Steven D'Aprano

Steven D'Aprano  added the comment:

By the way, there is no need to use the u'' prefix on strings in Python 3.

Unfortunately, I think this is a case where pprint doesn't meet your 
expectations. pprint is designed to print the repr of a string, while regular 
print prints the human-visible str:

>>> print(repr('\240 hello'))
'\xa0 hello'
>>> print('\240 hello')
  hello

Its not just non-breaking space, it also includes ASCII characters:


>>> print(repr('\01 hello'))
'\x01 hello'
>>> print('\01 hello')
 hello
>>> pprint.pprint('\01 hello')
'\x01 hello'


So this is intentional behaviour, not a bug. If you want to change the 
behaviour, it will probably require a re-design of the way strings are printed 
by the pprint module.

--
nosy: +steven.daprano

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



[issue42852] pprint fails in transformming non-breaking space

2021-01-07 Thread STINNER Victor


Change by STINNER Victor :


--
nosy:  -vstinner

___
Python tracker 

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



[issue42852] pprint fails in transformming non-breaking space

2021-01-06 Thread Xinmeng Xia


New submission from Xinmeng Xia :

"pprint" can transform unicode like "print". However, pprint fails to transform 
non-breaking space('\240') . See the following example:

Python 3.10.0a2 (default, Nov 24 2020, 14:18:46) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

Example 1(Results as expected):
-----
>>> import pprint
>>> print(u'\041 hello')
! hello
>>> pprint.pprint(u'\041 hello')
'! hello'

Example 2(Results not as expected):
-
>>> print(u'\240 hello')
  hello
>>> pprint.pprint(u'\240 hello')
'\xa0 hello'

Expected output: the output of pprint.pprint(u'\240 hello') should be 
consistent with output of print(u'\240 hello')

--
components: Unicode
messages: 384564
nosy: ezio.melotti, vstinner, xxm
priority: normal
severity: normal
status: open
title: pprint fails in transformming non-breaking space
type: behavior
versions: Python 3.10

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



[issue42259] pprint: infinite recursion for saferepr() when using nested objects, but str() works

2020-11-04 Thread Irit Katriel


Irit Katriel  added the comment:

I think this is a bug. There is recursion detection in pprint for dicts, lists 
and tuples, but it only applies when __repr__ has not been overridden in a 
subclass.

If you remove the __repr__ definition from NiceObject then str(s) works.

--
nosy: +iritkatriel
versions: +Python 3.10, Python 3.9

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



[issue42259] pprint: infinite recursion for saferepr() when using nested objects, but str() works

2020-11-04 Thread Danylo Hlynskyi


New submission from Danylo Hlynskyi :

First, here's an example using str():

```
class NiceObject:
def __str__(self):
return str(self.__dict__)
def __repr__(self):
return str(self)

s = NiceObject()
s.self = s
```
This outputs:
```
>>> s
{'self': {...}}
```

When I replace str() call with pprint.saferepr(), I end up in infinite 
recursion.
```
import pprint

class ReallyNiceObject:
def __str__(self):
return pprint.saferepr(self.__dict__)
def __repr__(self):
return str(self)
```

Same happens for pprint.pformat(), with depth set.

Is this expected behavior?

--
components: Library (Lib)
messages: 380315
nosy: danbst
priority: normal
severity: normal
status: open
title: pprint: infinite recursion for saferepr() when using nested objects, but 
str() works
type: behavior
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue42259>
___
___
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

2020-09-19 Thread Irit Katriel


Change by Irit Katriel :


--
assignee:  -> docs@python
components: +Documentation
nosy: +docs@python

___
Python tracker 

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



[issue39994] pprint handling of dict subclasses that override __repr__

2020-08-30 Thread Eric V. Smith


Change by Eric V. Smith :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue39994] pprint handling of dict subclasses that override __repr__

2020-08-30 Thread Irit Katriel


Irit Katriel  added the comment:

Thank you Serhiy.  This ticket can be closed now.

--

___
Python tracker 

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



[issue39994] pprint handling of dict subclasses that override __repr__

2020-08-30 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset 582f13786bb75c73d609790967fea03a5b50148a by Irit Katriel in 
branch 'master':
bpo-39994: Fix pprint handling of dict subclasses that override __repr__ 
(GH-21892)
https://github.com/python/cpython/commit/582f13786bb75c73d609790967fea03a5b50148a


--

___
Python tracker 
<https://bugs.python.org/issue39994>
___
___
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

2020-08-22 Thread Irit Katriel


Irit Katriel  added the comment:

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

According to https://docs.python.org/3/library/pprint.html compact impacts the 
way that sequences are displayed, and a dict is not a sequence.
So I'm not sure a documentation change is required.

--
nosy: +iritkatriel

___
Python tracker 

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



[issue41546] pprint() gives exception when ran from pythonw

2020-08-17 Thread Steve Dower


Steve Dower  added the comment:

I'm inclined to agree that it should pass silently in this case, as if it were 
printing with print() rather than .write().

What better meaning is there for sys.stdout == None than "no output"?

--
versions: +Python 3.10 -Python 3.8

___
Python tracker 

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



[issue41546] pprint() gives exception when ran from pythonw

2020-08-17 Thread Vedran Čačić

Vedran Čačić  added the comment:

The big part of the justification for making print a function in Py3 is that it 
can be painlessly replaced with other functions, such as (example given by 
BDFL) pprint.pprint. I think we should do what we can to make the replacement 
as painless as possible.

--
nosy: +veky

___
Python tracker 

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



  1   2   3   4   5   6   >