[Python-Dev] bpo-34595: How to format a type name? (original) (raw)

Barry Warsaw barry at python.org
Tue Sep 11 20:21:01 EDT 2018


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 PyUnicodeFromFormatV() and so indirectly to PyUnicodeFromFormat() and PyErrFormat():

https://bugs.python.org/issue34595 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.

-Barry



More information about the Python-Dev mailing list