8000 Import causes object id changes in other modules · Issue #11594 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content
Import causes object id changes in other modules #11594
Closed
@fragmuffin

Description

@fragmuffin

Description

I discovered that, in a very specific case, importing can disrupt object ids after they've already been imported and used.

Replicating Fault

I've attached a minimal subset of our code-base recreating the fault: bug-report.tar.gz

$ tree
.
├── lib
│   └── uboot
│       ├── forwarder.py
│       └── services
│           ├── __init__.py
│           └── webterm
│               ├── connect.py
│               └── __init__.py
├── test.py
└── test.sh

The test.py imports a submodule (webterm), and references an object it contains (webterm.connect).

...
from uboot.forwarder import webterm
function = type(lambda: None)

def test():
    if isinstance(webterm.connect, function):
        print("✅ Passed : {}".format(type(webterm.connect)))
    else:
        print("❌ Failed : {}".format(type(webterm.connect)))

test()
from uboot.services.webterm.connect import FOO  # <-- causes webterm.connect to change
test()

After importing a parallel object (referencing it more directly), the original value changes.

I believe the root cause of this may be due to the content of uboot.services.webterm.__init__.py:

from .connect import connect

Test Results (cPython vs micropython)

Note: This behaviour is not shared by cPython (not in v3.10, nor in v3.4 (micropython's original basis))

$ ./test.sh 
-------- sys.version=3.4.10 (default, Mar 20 2019, 00:52:37)  [GCC 6.3.0 20170516]
✅ Passed : <class 'function'>
✅ Passed : <class 'function'>
-------- sys.version=3.10.11 (main, May  3 2023, 09:20:51) [GCC 10.2.1 20210110]
✅ Passed : <class 'function'>
✅ Passed : <class 'function'>
-------- sys.version=3.4.0      ... results from micropython v1.18
✅ Passed : <class 'function'>
❌ Failed : <class 'module'>
-------- sys.version=3.4.0; MicroPython v1.20.0 on 2023-05-14
✅ Passed : <class 'function'>
❌ Failed : <class 'module'>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0