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/155167.html below:

[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
Wed Sep 12 20:33:23 EDT 2018
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
* Add ":T" format to type.__format__()
* Add "%t" and "%T" formatters to PyUnicode_FromUnicodeV()
* Add a read-only type.__fqn__ property


# Python: "!t" for instance
raise TypeError(f"must be str, not {obj!t}")

/* C: "%t" for instance */
PyErr_Format(PyExc_TypeError, "must be str, not %t", obj);


/* C: "%T" for type */
PyErr_Format(PyExc_TypeError, "must be str, not %T", mytype);

# Python: ":T" for type
raise TypeError(f"must be str, not {mytype!T}")


Open question: Should we also add "%t" and "%T" formatters to the str
% args operator at the Python level?

I have a proof-of-concept implementation:
https://github.com/python/cpython/pull/9251

Victor

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