Title: Use __qualname__ together with __module__
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: haypo, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2014-07-22 09:02 by serhiy.storchaka, last changed 2014-07-22 12:05 by serhiy.storchaka. This issue is now closed.

File name Uploaded Description Edit
repr_qualname.diff serhiy.storchaka, 2014-07-22 09:02 review
Messages (6)
msg223649 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-07-22 09:02
Often when class name is reported in stdlib (e.g. in reprs), it used together with module name: '%s.%s' % (self.__class__.__module__, self.__class__.__name__). But this code is wrong when a class is nested. The __qualname__ attribute should be used instead of just __name__ (and it is already used in multiple places).

Proposed patch replaces __name__ to __qualname__ when it used together with module name to format full class name.
msg223651 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2014-07-22 09:14
The patch looks good to me.

For Python 3.4, may it break the backward compatibility? For example, breaking doctests relying on the exact representation? If there is a risk, it's maybe safer to only modify Python 3.5.
msg223661 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-07-22 11:52
It broke Python tests (test_traceback and test_unittest), and the patch contains fixes for this. Yes, it can break user test if they test nested subclasses of classes touched by this patch. This is not very likely, but on other hand I don't see what can happen wrong when we will not fix it in 3.4.
msg223663 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2014-07-22 11:54
If an application relies on the exact representation in an unit test, it would be annoying to check the minor Python version to support the old and the new format.

Using the qualified name is better, but it can wait Python 3.5 IMO. They are enough complains that Python breaks backward compatibility, which is true or not :-)
msg223664 - (view) Author: Roundup Robot (python-dev) Date: 2014-07-22 12:00
New changeset fe3c98313855 by Serhiy Storchaka in branch 'default':
Issue #22032: __qualname__ instead of __name__ is now always used to format
msg223665 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-07-22 12:05
I agree with you. Thank for your review Victor.

All these issues are precursors to issue22033.
Date User Action Args
2014-07-22 12:05:15serhiy.storchakasetstatus: open -> closed
messages: + msg223665

assignee: serhiy.storchaka
resolution: fixed
stage: patch review -> resolved
2014-07-22 12:00:35python-devsetnosy: + python-dev
messages: + msg223664
2014-07-22 11:54:22hayposetmessages: + msg223663
2014-07-22 11:52:07serhiy.storchakasetmessages: + msg223661
versions: - Python 3.4
2014-07-22 09:14:40hayposetnosy: + haypo
messages: + msg223651
2014-07-22 09:02:36serhiy.storchakacreate