New submission from Petr Viktorin <encu...@gmail.com>:

One underlying issue from bpo-41631 is that importlib.util.LazyLoader produces 
modules that are only fully loaded after an attribute is accessed (through 
__getattribute__).

C-API functions like PyModule_GetState, PyModule_GetDict and such do not get 
attributes, and when called on a _LazyModule, they might try to access 
uninitialized C-level state.

I see two possible ways to fix this:
- Make PyModule_GetState, etc. trigger a full load. Since this is C-API, it 
would need a fast (no Python code) way either to do the full load or to detect 
_LazyModule.
- Make LazyLoader eager for either all extension & builtin modules, or for 
modules that have C-level storage. The latter would need a way to pass info 
from PyModuleDef to the loader.


Brett, does that analysis make sense from the importlib POV?

----------
components: C API
messages: 376991
nosy: brett.cannon, petr.viktorin
priority: normal
severity: normal
status: open
title: PyModule_GetState doesn't work with LazyLoader

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41797>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to