This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients eric.smith, serhiy.storchaka, vstinner
Date 2018-09-07.21:03:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1536354230.78.0.56676864532.issue34595@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-09-07 21:03:50serhiy.storchakasetrecipients: + serhiy.storchaka, vstinner, eric.smith
2018-09-07 21:03:50serhiy.storchakasetmessageid: <1536354230.78.0.56676864532.issue34595@psf.upfronthosting.co.za>
2018-09-07 21:03:50serhiy.storchakalinkissue34595 messages
2018-09-07 21:03:50serhiy.storchakacreate