[New-bugs-announce] [issue39506] operator |= on sets does not behave like the update method

Gabriele Tornetta report at bugs.python.org
Fri Jan 31 05:30:54 EST 2020


New submission from Gabriele Tornetta <phoenix1987 at gmail.com>:

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 <report at bugs.python.org>
<https://bugs.python.org/issue39506>
_______________________________________


More information about the New-bugs-announce mailing list