Pablo Galindo Salgado <pablog...@gmail.com> added the comment:

> as it's either the
variable should exist and have a value or it should be unknown and result
in NameError at this point.

One thing is the symbol and another thing is its value. The function is always 
aware of the existence of the symbol. For instance:

def f(x):
   del x
   print(x)

>>> print(f.__code__.co_varnames)
('x',)

But when the function tries to use it, it has no value associated to it because 
del x removed it, so it emits an UnboundLocalError because there is no value.

raceback (most recent call last):
  File "lel.py", line 7, in <module>
    f(3)
  File "lel.py", line 3, in f
    print(x)
UnboundLocalError: local variable 'x' referenced before assignment

A NameError will occur if the symbol is unknown to the function.

----------
nosy:  -christian.heimes

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40728>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to