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: except-clause with own exception class inside generator can lead to confusing warning on termination
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, hagen, pitrou, r.david.murray
Priority: normal Keywords:

Created on 2013-05-30 15:35 by hagen, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg190365 - (view) Author: Hagen Fürstenau (hagen) Date: 2013-05-30 15:35
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.
msg190366 - (view) Author: Hagen Fürstenau (hagen) Date: 2013-05-30 15:40
s/digged/dug/  :-)
msg190367 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-05-30 15:41
You are almost certainly correct.  MyException can get set to None during interpreter shutdown.  There are a couple of active issues and a PEP that address this type of problem, so this issue probably isn't needed, but I'll leave that up to Antoine, who is working on it.
msg190372 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-05-30 17:15
I will keep this issue alive so that I can check whether it is fixed by further changes.
msg199937 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-10-14 18:17
While this is easy to reproduce under 3.3, it doesn't happen anymore under 3.4. Given how tricky it would be to fix it under 3.3 (IMO), I prefer to close the bug.
History
Date User Action Args
2022-04-11 14:57:46adminsetgithub: 62302
2013-10-14 18:17:01pitrousetstatus: open -> closed
versions: - Python 3.4
messages: + msg199937

resolution: out of date
stage: resolved
2013-06-03 22:47:44ezio.melottisetnosy: + ezio.melotti
2013-05-30 17:15:45pitrousetmessages: + msg190372
versions: + Python 3.4
2013-05-30 15:41:30r.david.murraysetnosy: + r.david.murray, pitrou
messages: + msg190367
2013-05-30 15:40:51hagensetmessages: + msg190366
2013-05-30 15:35:59hagencreate