This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.smith
Recipients dirn, eric.smith, gregory.p.smith, paul.moore, serhiy.storchaka, steven.daprano, xtreak
Date 2019-05-02.19:25:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1556825127.28.0.623023950858.issue36774@roundup.psfhosted.org>
In-reply-to
Content
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?
History
Date User Action Args
2019-05-02 19:25:27eric.smithsetrecipients: + eric.smith, gregory.p.smith, paul.moore, steven.daprano, dirn, serhiy.storchaka, xtreak
2019-05-02 19:25:27eric.smithsetmessageid: <1556825127.28.0.623023950858.issue36774@roundup.psfhosted.org>
2019-05-02 19:25:27eric.smithlinkissue36774 messages
2019-05-02 19:25:27eric.smithcreate