[Python-Dev] bpo-34595: How to format a type name? (original) (raw)
Victor Stinner vstinner at redhat.com
Wed Sep 12 20:33:23 EDT 2018
- Previous message (by thread): [Python-Dev] bpo-34595: How to format a type name?
- Next message (by thread): [Python-Dev] bpo-34595: How to format a type name?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message (by thread): [Python-Dev] bpo-34595: How to format a type name?
- Next message (by thread): [Python-Dev] bpo-34595: How to format a type name?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]