Tim Peters added the comment:
Yes, the assignment does "hide the global definition of g". But this
determination is made at compile time, not at run time: an assignment to `g`
_anywhere_ inside `f()` makes _every_ appearance of `g` within `f()` local to
`f`.
--
nosy: +tim.peters
Eric V. Smith added the comment:
Python thinks that `g` inside `f()` is a local variable. See
https://stackoverflow.com/questions/9264763/unboundlocalerror-in-python#9264845
for an explanation.
This is working as intended.
--
nosy: +eric.smith
resolution: -> not a bug
stage: -> re
New submission from Camille :
In the following code :
def g():
return 0
def f():
g = g()
f()
The call to g in f fails due to an UnboundLocalError, while I expected the
assignment to hide the global definition of g. Note that if it is done in two
subsequent calls, i.e. with :
def f(