Author Gabriele Tornetta
Recipients Gabriele Tornetta
Date 2020-01-31.10:30:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1580466654.94.0.209518584933.issue39506@roundup.psfhosted.org>
In-reply-to
Content
def outer():
  a=set()
  def inner():
    a |= set(["A"])
  inner()
  return a

print(outer())

Traceback (most recent call last):
  File "main.py", line 8, in <module>
    print(outer())
  File "main.py", line 5, in outer
    inner()
  File "main.py", line 4, in inner
    a |= set(["A"])
UnboundLocalError: local variable 'a' referenced before assignment

However, the update method works as expected:

def outer():
  a=set()
  def inner():
    a.update(set(["A"]))
  inner()
  return a

print(outer())

{'A'}
History
Date User Action Args
2020-01-31 10:30:54Gabriele Tornettasetrecipients: + Gabriele Tornetta
2020-01-31 10:30:54Gabriele Tornettasetmessageid: <1580466654.94.0.209518584933.issue39506@roundup.psfhosted.org>
2020-01-31 10:30:54Gabriele Tornettalinkissue39506 messages
2020-01-31 10:30:54Gabriele Tornettacreate