<p dir="ltr"><br>
On 17 Dec 2013 02:23, "Eric V. Smith" <<a href="mailto:eric@trueblade.com">eric@trueblade.com</a>> wrote:<br>
><br>
> On 12/16/2013 10:29 AM, Walter Dörwald wrote:<br>
> > I'd vote for including the module name in the string and using<br>
> > __qualname__ instead of __name__, i.e. make "{:T}".format(obj)<br>
> > equivalent to<br>
> > "{0.__class__.__module__}.{0.__class__.qualname__}".format(obj).<br>
><br>
> That's not possible in general. The format specifier interpretation is<br>
> done by each type. So, you could add this to str.__format__ and<br>
> int.__format__, but you can't add it to an arbitrary type's __format__.<br>
> For example, types not in the stdlib would never know about it.</p>
<p dir="ltr">That just suggests it would need to be a type coercion code, like !a, !r, and !s. However, that observation also suggests that starting with a "classname" or "typename" builtin would be more appropriate than jumping directly to a formatting code.</p>

<p dir="ltr">We've definitely drifted well into python-ideas territory at this point, though :)</p>
<p dir="ltr">Cheers,<br>
Nick.</p>
<p dir="ltr">><br>
> There's no logic for calling through to object.__format__ for unknown<br>
> specifiers. Look at datetime, for example. It uses strftime, so "T"<br>
> currently just prints a literal "T".<br>
><br>
> And for object.__format__, we recently made it an error to specify any<br>
> format string. This is to prevent you from calling<br>
> format(an_object, ".30")<br>
> and "knowning" that it's interpreted by str.__format__ (because that's<br>
> the default conversion for object.__format__). If in the future<br>
> an_object's class added its own __format__, this code would break (or at<br>
> least do the wrong thing).<br>
><br>
> But I really do like the idea! Maybe there's a way to just make<br>
> obj.__class__ recognize "T", so you could at least do:<br>
> format(obj.__class__, "T")<br>
> or equivalently:<br>
> "{:T}".format(obj.__class__)<br>
><br>
> I realize that having to use .__class__ defeats some of the beauty of<br>
> this scheme.<br>
><br>
> Eric.<br>
><br>
><br>
> _______________________________________________<br>
> Python-Dev mailing list<br>
> <a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-dev">https://mail.python.org/mailman/listinfo/python-dev</a><br>
> Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com">https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com</a><br>
</p>