[New-bugs-announce] [issue45705] |= set update scoping

James Bowery report at bugs.python.org
Wed Nov 3 16:24:40 EDT 2021


New submission from James Bowery <jabowery at gmail.com>:

Comment out the |= line and it prints "{'b':2}" as expected.

$ cat t.py
scoped_dict = {'b':2}
def scoped_def():
    print(scoped_dict)
    scoped_dict |= {'a',1}
scoped_def()

$ p t.py 
Traceback (most recent call last):
  File "/home/jabowery/dev/t.py", line 5, in <module>
    scoped_def()
  File "/home/jabowery/dev/t.py", line 3, in scoped_def
    print(scoped_dict)
UnboundLocalError: local variable 'scoped_dict' referenced before assignment

$ python --version
Python 3.10.0

----------
components: Parser
messages: 405643
nosy: jabowery2, lys.nikolaou, pablogsal
priority: normal
severity: normal
status: open
title: |= set update scoping
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45705>
_______________________________________


More information about the New-bugs-announce mailing list