On 09/13/2018 07:01 AM, Eric V. Smith wrote:
On 9/12/2018 8:33 PM, Victor Stinner wrote:

Hi,

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
proposal:

* 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
   strong reference.
 * 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.


Cheers,


//arry/
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to