Skip to content

object has different identities during and after import #2687

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy