Convert bug (when liscomp inside a function with nonlocal)
Closed this issue · 0 comments
yunline commented
Original script:
def func():
i=0
def func2():
nonlocal i
i=2
l = [print(i) for i in range(10)]
func2()
print(i)
func()
Output script (formated by black):
[
(
func := (
lambda: [
(__ol_retv_etqyzkytpj := None),
(__ol_nonlocal_hrimcakmce := {}),
__ol_nonlocal_hrimcakmce.__setitem__("i", 0),
(
func2 := (
lambda: [
(__ol_retv_pexorfzhzg := None),
__ol_nonlocal_hrimcakmce.__setitem__("i", 2),
(
l := [
print(__ol_nonlocal_hrimcakmce["i"])
for i in range(10)
]
),
__ol_retv_pexorfzhzg,
][-1]
)
),
func2(),
print(__ol_nonlocal_hrimcakmce["i"]),
__ol_retv_etqyzkytpj,
][-1]
)
),
func(),
]
The list comprehension [print(i) for i in range(10)]
is converted as l := [print(__ol_nonlocal_hrimcakmce["i"]) for i in range(10)]
, which makes the output of script different. This is a bug.