New submission from Gabriele Tornetta <[email protected]>:
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'}
----------
components: Interpreter Core
messages: 361097
nosy: Gabriele Tornetta
priority: normal
severity: normal
status: open
title: operator |= on sets does not behave like the update method
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue39506>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com