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

IIRC there is similar issue or a discussion on one of mailing lists. But the 
idea about adding this feature on Python side too was considered. It would be 
better to find this discussion before pushing this change.

In some cases we have the type itself, not an instance. So it makes sense to 
make %T an equivalent of arg->tp_name instead of Py_TYPE(arg)->tp_name.

On Python side, you need to output either short name obj.__class__.__name__ or 
full qualified name obj.__class__.__module__ + '.' + obj.__class__.__qualname__ 
with exception that the module name should be omitted if it is 'builtins'.

    obj.__class__.__qualname__ if obj.__class__.__module__ == 'builtins' else 
f'{obj.__class__.__module__}.{obj.__class__.__qualname__}'

The case of the module name '__main__' can be handled specially too.
Obviously it is desirable to have a more handy way of writing such expression.

On C side, the problem is that tp_name means different, depending of the kind 
of the type. In some cases it is a short name, in other cases it is a full 
qualified name. It is not easy to write a code that produces the same output in 
Python and C. I have added a helper _PyType_Name() that helps to solve a part 
of these issues. If you want to output a short name (just cls.__name__ in 
Python), use _PyType_Name(cls) instead of cls->tp_name. But this doesn't help 
for the case when you need to output a full qualified name.

----------
nosy: +serhiy.storchaka

_______________________________________
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