A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2018-September/155182.html below:

[Python-Dev] bpo-34595: How to format a type name?

[Python-Dev] bpo-34595: How to format a type name? [Python-Dev] bpo-34595: How to format a type name?Victor Stinner vstinner at redhat.com
Thu Sep 13 20:04:53 EDT 2018
Le ven. 14 sept. 2018 à 00:09, Eric V. Smith <eric at trueblade.com> a écrit :
> f'{type(obj)}' becomes type(obj).__format__(''), so you can return
> something other than __str__ or __repr__ does. It's only by convention
> that an object's __format__ returns __str__: it need not do so.

What's New in Python 3.7 contains:

> object.__format__(x, '') is now equivalent to str(x) rather than format(str(self), '').
> (Contributed by Serhiy Storchaka in bpo-28974.)

https://bugs.python.org/issue28974

Oh, I didn't know that a type is free to change this behavior: return
something different than str(obj) if the format spec is an empty
string.

So are you suggesting to change type(obj).__format__('') to return the
fully qualified name instead of repr(type)?

So "%s" % type(obj) would use repr(), but "{}".format(type(obj)) and
f"{type(obj)}" would return the fully qualified name?

Victor
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4