How can I check whether a lazy import has executed in Python 3.15 without triggering it?
I'm testing the new lazy imports in Python 3.15. I have a module called example.py: print("Module executed") value = 42 And this code in main.py: lazy import example print("Checking module") print(hasattr(example, "value")) print(example.value) I want to check whether the module has already been executed without causing it to execute. The problem is that hasattr() accesses the module's attributes, which appears to trigger the lazy import. I also considered checking sys.modules: import sys lazy import example print("example" in sys.modules) But I'm not sure whether this is a reliable way to che
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.