What are the cases where `PyModule_Create` returns null

what are the cases where PyModule_Create returns null ?

You can work a lot of it out from the source, although it’s difficult to be absolutely comprehensive: cpython/Objects/moduleobject.c at 77b45fa6d0b8c0c14657b5117b21a3f3f2ce97d8 · python/cpython · GitHub

  • Import machinery not initialized,
  • api version doesn’t match (although this’ll only apply to PyModule_Create2 I think),
  • module contains m_slots,
  • Memory allocation fails,
  • Probably passing a null string as a name,
  • Module functions defined with METH_CLASS or METH_STATIC,

Most of the things that can fail are probably memory allocation failures, which are fairly unlikely but can happen pretty much anywhere.


okey thanks you for your answer