[New-bugs-announce] [issue18102] except-clause with own exception class inside generator can lead to confusing warning on termination

Hagen Fürstenau report at bugs.python.org
Thu May 30 17:35:59 CEST 2013


New submission from Hagen Fürstenau:

The following code will sometimes warn about an ignored TypeError('catching classes that do not inherit from BaseException is not allowed',) on termination:


class MyException(Exception):
    pass

def gen():
    try:
        yield
    except MyException:
        pass

g = gen()
next(g)


Of course, MyException inherits from Exception, so there should be no problem.

Apparently, MyException gets destroyed before the generator object (at least sometimes, presumably depending on the hash randomization seed), and the destructor of the generator object then complains because there is no MyException any more. At least that's my explanation of this, without having digged into the code.

----------
components: Interpreter Core
messages: 190365
nosy: hagen
priority: normal
severity: normal
status: open
title: except-clause with own exception class inside generator can lead to confusing warning on termination
type: behavior
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18102>
_______________________________________


More information about the New-bugs-announce mailing list