MRAB wrote on 9/11/18 16:06:
On 2018-09-11 23:23, Victor Stinner wrote:
Last week, I opened an issue to propose to add a new %T formatter to PyUnicode_FromFormatV() and so indirectly to PyUnicode_FromFormat() and PyErr_Format():
I merged my change, but then Serhiy Storchaka asked if we can add something to get the "fully qualified name" (FQN) of a type, ex "datetime.timedelta" (FQN) vs "timedelta" (what I call "short" name). I proposed a second pull request to add %t (short) in addition to %T (FQN).
But then Petr Viktorin asked me to open a thread on python-dev to get a wider discussion. So here I am.
+1 for adding format specs for the types, and for giving a consistent way to specify which you want. %t (short) and %T (long) do seem like the logical choices, and I think in context it'll be pretty evident what they mean.
Perhaps we could have a single format code plus an optional '#' for the "alternate form":
%T for short form %#T for fully qualified name
OTOH, if %T and variants meant "type" but %t mean something entirely different, that *would* probably be confusing.