[Python-Dev] bpo-34595: How to format a type name?
larry at hastings.org
Thu Sep 13 14:20:36 EDT 2018
On 09/13/2018 07:01 AM, Eric V. Smith wrote:
> On 9/12/2018 8:33 PM, Victor Stinner wrote:
>> For the type name, sometimes, we only get a type (not an instance),
>> and we want to format its FQN. IMHO we need to provide ways to format
>> the FQN of a type for *types* and for *instances*. Here is my
>> * Add !t conversion to format string
> I'm strongly opposed to this. This !t conversion would not be widely
> applicable enough to be generally useful, and would need to be exposed
> in the f-string and str.format() documentation, even though 99% of
> programmers would never need or see it.
I discussed this with Eric in-person this morning at the core dev
sprints. Eric's understanding is that this is motivated by the fact
that Py_TYPE() returns a borrowed reference, and by switching to this !t
conversion we could avoid using Py_TYPE() when formatting error
messages. My quick thoughts on this:
* If Py_TYPE() is a bad API, then it's a bad API and should be
replaced. We should have a new version of Py_TYPE() that returns a
* If we're talking about formatting error messages, we're formatting
an exception, which means we're already no longer in
performance-sensitive code. So we should use the new API that
returns a strong reference. The negligible speed hit of taking the
extra reference will be irrelevant.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev