[issue39841] "as" variable in except block deletes local variables with same name
Eric V. Smith
report at bugs.python.org
Tue Mar 3 16:27:49 EST 2020
Eric V. Smith <eric at trueblade.com> added the comment:
Yes, this is a known issue.
See https://docs.python.org/3/reference/compound_stmts.html#the-try-statement, in particular the sentence "When an exception has been assigned using as target, it is cleared at the end of the except clause" and the following text.
Basically, at the end of the exception block python does a "del err" in order to prevent a long-lived reference cycle including the exception.
----------
nosy: +eric.smith
resolution: -> not a bug
stage: -> resolved
status: open -> closed
type: -> behavior
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39841>
_______________________________________
More information about the Python-bugs-list
mailing list