.. index:: single: ModuleType (in module types)
This instance of :c:type:`PyTypeObject` represents the Python module type. This
- is exposed to Python programs as ``types.ModuleType``.
+ is exposed to Python programs as :py:class:`types.ModuleType`.
.. c:function:: int PyModule_Check(PyObject *p)
``PyObject_*`` functions rather than directly manipulate a module's
:attr:`~object.__dict__`.
+ The returned reference is borrowed from the module; it is valid until
+ the module is destroyed.
+
.. c:function:: PyObject* PyModule_GetNameObject(PyObject *module)
Similar to :c:func:`PyModule_GetNameObject` but return the name encoded to
``'utf-8'``.
+ The returned buffer is only valid until the module is renamed or destroyed.
+ Note that Python code may rename a module by setting its :py:attr:`~module.__name__`
+ attribute.
+
.. c:function:: void* PyModule_GetState(PyObject *module)
Return the "state" of the module, that is, a pointer to the block of memory
Similar to :c:func:`PyModule_GetFilenameObject` but return the filename
encoded to 'utf-8'.
+ The returned buffer is only valid until the module's :py:attr:`~module.__file__` attribute
+ is reassigned or the module is destroyed.
+
.. deprecated:: 3.2
:c:func:`PyModule_GetFilename` raises :exc:`UnicodeEncodeError` on
unencodable filenames, use :c:func:`PyModule_GetFilenameObject` instead.
:c:type:`PyMethodDef` arrays; in that case they should call this function
directly.
+ The *functions* array must be statically allocated (or otherwise guaranteed
+ to outlive the module object).
+
.. versionadded:: 3.5
.. c:function:: int PyModule_SetDocString(PyObject *module, const char *docstring)