8000 object has different identities during and after import · Issue #2687 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content
object has different identities during and after import #2687
Closed
@dhalbert

Description

@dhalbert

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0