Issue 28559: Unclear error message when raising wrong type of exceptions (original) (raw)

Issue28559

Created on 2016-10-29 18:16 by Dimitri Merejkowsky, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
0001-Fix-error-message-when-raising-with-the-wrong-type.patch Dimitri Merejkowsky,2016-10-29 18:16
Messages (2)
msg279689 - (view) Author: Dimitri Merejkowsky (Dimitri Merejkowsky) * Date: 2016-10-29 18:16
Motivation for the patch came from a tweet[1] of David Beazley: def SomeError(Exception): pass raise SomeError('blah') (Note the `def` keyword instead of `class`): If you run that, you get: > TypeError: exceptions must derive from BaseException Which is not very helpful. Attached patch changes the error message to be: > TypeError: exceptions must derive from BaseException, got NoneType (By the way, it's very close to what Python2 used to say in this case)
msg280238 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-11-07 20:49
Thanks for the patch, but I find your proposed message less clearer (including NoneType adds unnecessary confusion and people may ask "where did NoneType come from?") Python 2 is different because of historical reasons (pre-BaseException era) so I don't think we should look at it in this case. If other core developers give their +1s, the patch needs to be updated to add a test case (it can be added to Lib/test/test_exceptions.py) and use the Py_TYPE() macro instead of accessing exc->ob_type directly.
History
Date User Action Args
2022-04-11 14:58:38 admin set github: 72745
2021-12-10 09:50:22 iritkatriel set status: pending -> closedresolution: rejectedstage: patch review -> resolved
2019-03-31 14:39:12 serhiy.storchaka set status: open -> pending
2016-12-23 22:49:03 levkivskyi set nosy: + levkivskyi
2016-11-07 20:49:36 berker.peksag set nosy: + berker.peksagmessages: + stage: patch review
2016-10-29 18:16:31 Dimitri Merejkowsky create