Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

> Ok, I wrote PR 9122 to add %t format and modify %T format:

Nice!

I agree that it is easy to use _PyType_Name() directly. But using 
_PyType_FullName() instead of tp_name can be cumbersome because it returns a 
new object and needs error handling.

> Or do you want to add a new formatter to type.__format__() to expose %T at 
> the Python level, f"{type(obj).__module__}.{type(obj).__qualname__}"?

Yes, I think we need a convenient way of formatting fully qualified name that 
omits the module name for types in the builtins module. It is equivalent to 
Py_TYPE(obj)->tp_name for extension types which is the most popular way to 
format a type name in error messages for now.

There are several open issues for inconsistency in error messages for Python 
and C implementations, because the former use type(obj).__name__ or 
obj.__class__.__name__, and the latter use Py_TYPE(obj)->tp_name. I hope 
finally we will fix this.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34595>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to