Commit b72cc5f
Implement Py_mod_create slot support in multi-phase init
Following CPython's implementation, now properly use the create slot
if provided, instead of always using default module creation.
CPython flow (Objects/moduleobject.c PyModule_FromDefAndSpec):
- If Py_mod_create slot exists: call create(spec, def)
- Otherwise: use PyModule_NewObject() for default creation
RustPython now follows the same pattern:
- If slots.create exists: call create(vm, spec, def)
- Otherwise: use PyModule::from_def() + __init_dict_from_def()
This allows modules to provide custom module objects during creation
phase, enabling advanced use cases like singleton modules or modules
with special initialization requirements.
Tested:
- Basic imports work correctly
- sha256/sha512 with custom exec still work
- test_pickle, test_pickletools, test_hashlib all pass
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 1eaf55d commit b72cc5f
1 file changed
+11
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
109 | 115 | | |
110 | 116 | | |
111 | 117 | | |
| |||
0 commit comments