Closed
Description
nested.py:
l = [[]]
l0 = l[0]
print("l[0]", id(l[0]))
print(l0, id(l0))
Adafruit CircuitPython 3.1.2 on 2019-01-07; Adafruit Metro M0 Express with samd21g18
>>> from nested import *
l[0] 536876704
[] 536876704
>>> id(l[0])
536876704
>>> id(l0)
536896144 # should not be different from id(l[0])
>>>
In CircuitPython 2.x, MicroPython, and CPython the id()
values are the same in the REPL. My guess is that this has to do with making an object long-lived during compilation, since this shows up in 3.x.
Thanks @TG-Techie for spotting this. This is reduced from a real program, in which he was fetching and assigning some empty lists nested inside some tuples during an import, and then found out they were not the same lists when referenced by subscript outside.
Tagging @tannewt.