Skip to content

importing twice triggers load #56

@dvincentwest

Description

@dvincentwest

Problem

When importing a module setup with apipkg, successive imports, even if in different files, trigger a full load. I thought it would only load when actually used. I have some anecdotal observation that the behavior is intermittent, but when I put together this test code, it reproduces every time

How to Reproduce

system info:

MacOS 14.5
Python 3.12.4

Consider the following filetree

mypkg/
  - module.py
  - lazy.py

with contents:

# lazy.py
import apipkg
apipkg.initpkg(__name__,{
        "module": "mypkg.module",
    })
# module.py
print("module loaded")

then in a terminal:

> python
>>> import mypkg.lazy.module
>>> import mypkg.lazy.module
module loaded

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