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.

classification
Title: Need to use the exception class qualname when rendering exception (in C code)
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: DiddiLeija, iritkatriel, lukasz.langa, miss-islington, pablogsal, serhiy.storchaka, vstinner
Priority: Keywords: patch

Created on 2021-09-01 21:46 by iritkatriel, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 28119 merged iritkatriel, 2021-09-01 23:52
PR 28134 merged miss-islington, 2021-09-03 07:30
PR 28135 merged miss-islington, 2021-09-03 07:30
Messages (13)
msg400873 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-09-01 21:46
iritkatriel@Irits-MBP cpython % cat exc.py 

class A:
  class B:
    class E(Exception):
      pass

raise A.B.E()

iritkatriel@Irits-MBP cpython % cat test.py 

import exc


iritkatriel@Irits-MBP cpython % ./python.exe test.py 
Traceback (most recent call last):
  File "/Users/iritkatriel/src/cpython/test.py", line 2, in <module>
    import exc
    ^^^^^^^^^^
  File "/Users/iritkatriel/src/cpython/exc.py", line 7, in <module>
    raise A.B.E()
    ^^^^^^^^^^^^^
exc.E




==============
See the last line of the output: there is no such thing as exc.E. There is exc.A.B.E.

The traceback module doesn't have this issue:

iritkatriel@Irits-MBP cpython % cat test.py 

import traceback

try:
  import exc
except Exception as e:
  traceback.print_exception(e)


iritkatriel@Irits-MBP cpython % ./python.exe test.py 
Traceback (most recent call last):
  File "/Users/iritkatriel/src/cpython/test.py", line 5, in <module>
    import exc
    ^^^^^^^^^^
  File "/Users/iritkatriel/src/cpython/exc.py", line 7, in <module>
    raise A.B.E()
    ^^^^^^^^^^^^^
exc.A.B.E
msg400886 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-09-02 00:04
I've reproduced this on 3.9 and 3.10 as well.
msg400983 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-03 07:30
New changeset b4b6342848ec0459182a992151099252434cc619 by Irit Katriel in branch 'main':
bpo-45083: Include the exception class qualname when formatting an exception (GH-28119)
https://github.com/python/cpython/commit/b4b6342848ec0459182a992151099252434cc619
msg401005 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-03 16:56
New changeset 41c23740243cc3a0699bc4d5dcfd47a0007ff039 by Miss Islington (bot) in branch '3.9':
[3.9] bpo-45083: Include the exception class qualname when formatting an exception (GH-28119) (GH-28135)
https://github.com/python/cpython/commit/41c23740243cc3a0699bc4d5dcfd47a0007ff039
msg401400 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-08 16:32
New changeset 6b996d61c96222d959d043b9424e8125c0efbb27 by Miss Islington (bot) in branch '3.10':
[3.10] bpo-45083: Include the exception class qualname when formatting an exception (GH-28119) (GH-28134)
https://github.com/python/cpython/commit/6b996d61c96222d959d043b9424e8125c0efbb27
msg401401 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-08 16:33
Thanks, Irit! ✨ 🍰 ✨
msg401403 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-09-08 16:34
> New changeset 6b996d61c96222d959d043b9424e8125c0efbb27 by Miss Islington (bot) in branch '3.10':

Pablo wrote that new changes in the 3.10 branch will only land in 3.10.1. It means that Python 3.10.0 and 3.10.1 will produce different exception messages. It is going to be an issue, no?

You should either ask for an exception to Pablo, or revert the change.
msg401413 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-09-08 17:28
Pablo wanted to wait for 3.10.1, see https://github.com/python/cpython/pull/28134#issuecomment-912679271
msg401456 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-09-09 10:00
I reopen the issue. I'm not comfortable with the backport.

For me, this change is not a bugfix, but a new feature. It can break applications which rely on the exact error message in their test suite. I'm not sure why it was backported to Python 3.9. Moreover, I'm not comfortable to backport it to 3.10.1 and not 3.10.0.

I would prefer to only change the behavior in Python 3.11. If you want to get it in 3.10, I suggest to convince Pablo to get in 3.10.0.

Otherwise, I suggest to revert it in 3.9 and 3.10.

Well, the qualified name is usually the same than the short name, so only few applications should be impacted. But it's annoying when the Python behavior changes in a minor version (3.x.y).
msg401459 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-09-09 10:12
"{__module__}.{__name__}" is just incorrect reference if __name__ != __qualname__. Error messages should always use "{__module__}.{__qualname__}" or just "{__name__}". I see this as a bug. Fortunately very few code is affected.
msg401498 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-09 16:54
I agree with Serhiy, I consider this a bugfix. Let's raise it to "release blocker" to let Pablo decide if this should wait for 3.10.1 or get bumped up to 3.10.0.
msg401504 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-09-09 17:56
If the change is considered as a bugfix, it can wait for the next 3.9.x and 3.10.x release.

If it's considered as a feature (which is backward incompatible), it should only land in 3.10 if it's in 3.10.0, but be reverted in the 3.9 branch.

Honestly, I don't care about which option is taken, I'm just worried about the consistency of branches.
msg401788 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-09-14 18:53
The bug is not a crash in the interpreter and this PR touches fundamental code in the interpreter, so I think the safest approach is waiting for 3.10.1
History
Date User Action Args
2022-04-11 14:59:49adminsetgithub: 89246
2021-09-15 17:36:44serhiy.storchakasetstatus: open -> closed
resolution: fixed
2021-09-15 17:25:05DiddiLeijasetnosy: + DiddiLeija
2021-09-14 18:53:39pablogsalsetpriority: release blocker ->

messages: + msg401788
2021-09-09 17:56:39vstinnersetmessages: + msg401504
2021-09-09 16:54:25lukasz.langasetpriority: normal -> release blocker
nosy: + pablogsal
messages: + msg401498

2021-09-09 10:12:42serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg401459
2021-09-09 10:00:08vstinnersetstatus: closed -> open
resolution: fixed -> (no value)
messages: + msg401456
2021-09-08 17:28:19iritkatrielsetmessages: + msg401413
2021-09-08 16:34:22vstinnersetmessages: + msg401403
2021-09-08 16:33:01lukasz.langasetstatus: open -> closed
resolution: fixed
messages: + msg401401

stage: patch review -> resolved
2021-09-08 16:32:26lukasz.langasetmessages: + msg401400
2021-09-03 16:56:12lukasz.langasetmessages: + msg401005
2021-09-03 07:30:47lukasz.langasetnosy: + lukasz.langa
messages: + msg400983
2021-09-03 07:30:44miss-islingtonsetpull_requests: + pull_request26573
2021-09-03 07:30:40miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request26572
2021-09-02 13:06:54vstinnersetnosy: + vstinner
2021-09-02 00:04:14iritkatrielsetmessages: + msg400886
versions: + Python 3.9, Python 3.10
2021-09-01 23:57:43iritkatrielsettitle: Incorrect exception output in C -> Need to use the exception class qualname when rendering exception (in C code)
2021-09-01 23:52:04iritkatrielsetkeywords: + patch
stage: patch review
pull_requests: + pull_request26560
2021-09-01 21:46:35iritkatrielcreate