[issue41312] add !p to pprint.pformat() in str.format() an f-strings

2020-07-16 Thread Eric V. Smith


Eric V. Smith  added the comment:

I suggest you discuss this on python-ideas, since we'll need to reach consensus 
there, first.

--
components: +Interpreter Core -IO, Library (Lib)

___
Python tracker 

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



[issue41312] add !p to pprint.pformat() in str.format() an f-strings

2020-07-16 Thread Charles Machalow


Charles Machalow  added the comment:

In terms of multiple parameters, I propose adding a method to control the 
defaults used by !p.

Though the defaults would work more than well enough for basic log and print 
usage.

--

___
Python tracker 

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



[issue41312] add !p to pprint.pformat() in str.format() an f-strings

2020-07-16 Thread Eric V. Smith


Eric V. Smith  added the comment:

I agree with Raymond that it's unlikely that this will work, as a practical 
matter. In addition to the other problems mentioned, there's the issue of the 
many parameters to control pprint.

And I agree with pprint, or a replacement, needing a redesign. I think it 
should use singledispatch.

--

___
Python tracker 

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



[issue41312] add !p to pprint.pformat() in str.format() an f-strings

2020-07-16 Thread Charles Machalow


Charles Machalow  added the comment:

One of the key things for ppformat here is to format long spanning dicts/lists 
to multiple lines, that look easy to read in a log. I feel as though that 
feature/usefulness outweigh potential indentation weirdness.

A lot of the usage would probably be towards the end of an fstring.

--

___
Python tracker 

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



[issue41312] add !p to pprint.pformat() in str.format() an f-strings

2020-07-16 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

If the python-ideas discussion is fruitful, go ahead and re-open this tracker 
item.

Personally, I don't see how this would work.  The pretty printing routines rely 
on knowing their current level of indentation.  Also, much of the "prettiness" 
comes from making the output span multiple lines, so this wouldn't fit well in 
the middle of an f-string.  Lastly, the pprint module leaves a lot to be 
desired and likely needs a rewrite from scratch, so it wouldn't be wise to tie 
it directly to a core language feature.

--
nosy: +rhettinger
resolution:  -> later
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



[issue41312] add !p to pprint.pformat() in str.format() an f-strings

2020-07-15 Thread Charles Machalow


Charles Machalow  added the comment:

Fair enough. Didn't really know that list existed. Sent this there. Awaiting 
moderator approval. Thanks.

--

___
Python tracker 

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



[issue41312] add !p to pprint.pformat() in str.format() an f-strings

2020-07-15 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

This needs discussion on python-ideas/ideas category on discourse similar to 
f-string debug notation.

--
nosy: +eric.smith, xtreak

___
Python tracker 

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



[issue41312] add !p to pprint.pformat() in str.format() an f-strings

2020-07-15 Thread Charles Machalow


New submission from Charles Machalow :

Right now in str.format(), we have !s, !r, and !a to allow us to call str(), 
repr(), and ascii() respectively on the given expression.

I'm proposing that we add a !p conversion to have pprint.pformat() be called to 
convert the given expression to a 'pretty' string.

Calling
```
print(f"My dict: {d!p}")
```

is a lot more concise than:

```
import pprint
print(f"My dict: {pprint.pformat(d)}")
```

We may even be able to have a static attribute stored to change the various 
default kwargs of pprint.pformat().

--
components: IO, Library (Lib)
messages: 373738
nosy: Charles Machalow
priority: normal
severity: normal
status: open
title: add !p to pprint.pformat() in str.format() an f-strings
type: enhancement
versions: Python 3.10

___
Python tracker 

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