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)
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.