[issue40728] UnboundLocalError as a result of except statement variable re-assignment

Pablo Galindo Salgado report at bugs.python.org
Fri May 22 07:15:13 EDT 2020


Pablo Galindo Salgado <pablogsal at gmail.com> added the comment:

>But then why I still can access this variable? Shouldn't it then be
resulting in NameError as it's undefined variable at this point of time?

I don't think so, this is the same as if you do:

def f(exc):
   del exc
   return exc

>>> f(3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "lel.py", line 3, in f
    return exc
UnboundLocalError: local variable 'exc' referenced before assignment

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40728>
_______________________________________


More information about the Python-bugs-list mailing list