Eric V. Smith <e...@trueblade.com> added the comment:

Re: format specs and what they apply to.

The problem is that you want f"{expr!d}" to expand to f"expr={repr(expr)}". And 
I think you want that because it's the most useful behavior for strings. 
Without the repr it's not very useful for strings.

But you want to have the format spec apply to the expression, not the repr of 
the expression. So maybe f"{expr!d:spec}" should expand to 
f"expr={repr(format(expr, spec))}"

So
f"{datetime.now()!d:%Y-%m-%d}"
would become:
f"datetime.now()={repr(format(datetime.now(), '%Y-%m-%d'))}"
but that gives:
"datetime.now()='2019-05-02'"

Do we want the repr of the resulting string here (the single quotes around 
2019-05-02)? I think probably no (think float formatting).

So the question is: how do you get repr by default, but allow the format spec?

The only thing I've come up with is:
- f"{expr!d}" expands to f"expr={repr(expr)}", but
- f"{expr!d:spec} expands to f"expr={format(expr, spec)}"

I think this is the most useful version. But is it too complex to explain?

----------

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

Reply via email to