pyo3 icon indicating copy to clipboard operation
pyo3 copied to clipboard

RFC: Implement Multi-Phase Module Initialization as per PEP 489

Open Aequitosh opened this issue 1 year ago • 12 comments

RFC: Multi-Phase Module Initialization as per PEP 489

This PR implements multi-phase initialization in PyO3 as a drop-in replacement for single phase initialization. While it still needs some polish here and there, the implementation is mostly complete.

What's still left to do:

  • [x] Figure out how to add submodules again - needs some kind of support for creating m_slots or perhaps an API around creating PyModuleDefs
    • This works now, thanks to a mechanism that makes it possible to (de-facto) statically allocate m_slots at runtime.
  • [ ] Reliably get a Py<PyModule> from a *mut ffi::PyModuleDef
    • Is this even possible? If not, we'll require some API breaking, I fear
  • [ ] Improve error handling - currently panics if calling the module setup function (#ident(#(#module_args),*) in proc macros) fails
  • [ ] Implement multi-phase initialization for PyModule::new_bound
    • I wonder if this is actually necessary, though.
  • [ ] Address remaining TODOs
  • [ ] Rephrase commit messages / perhaps split up commits
    • The messages could IMO be somewhat more detailed, elaborating on the reasoning behind certain changes / additions

Please let me know what you think! I'm grateful for any feedback! :)

Specifically, I'd be very happy to receive insight / comments on the TODOs I've added here and there.

Aequitosh avatar May 06 '24 17:05 Aequitosh

Upgraded this PR from a draft to an RFC. The description was also updated to reflect that.

Aequitosh avatar Jul 23 '24 15:07 Aequitosh