@@ -778,12 +778,12 @@ class cpp_function : public function {
778778};
779779
780780// / Wrapper for Python extension modules
781- class module : public object {
781+ class module_ : public object {
782782public:
783- PYBIND11_OBJECT_DEFAULT (module , object, PyModule_Check)
783+ PYBIND11_OBJECT_DEFAULT (module_ , object, PyModule_Check)
784784
785785 // / Create a new top-level Python module with the given name and docstring
786- explicit module (const char *name, const char *doc = nullptr ) {
786+ explicit module_ (const char *name, const char *doc = nullptr ) {
787787 if (!options::show_user_defined_docstrings ()) doc = nullptr ;
788788#if PY_MAJOR_VERSION >= 3
789789 PyModuleDef *def = new PyModuleDef ();
@@ -797,7 +797,7 @@ class module : public object {
797797 m_ptr = Py_InitModule3 (name, nullptr , doc);
798798#endif
799799 if (m_ptr == nullptr )
800- pybind11_fail (" Internal error in module::module ()" );
800+ pybind11_fail (" Internal error in module_::module_ ()" );
801801 inc_ref ();
802802 }
803803
@@ -807,7 +807,7 @@ class module : public object {
807807 details on the ``Extra&& ... extra`` argument, see section :ref:`extras`.
808808 \endrst */
809809 template <typename Func, typename ... Extra>
810- module &def (const char *name_, Func &&f, const Extra& ... extra) {
810+ module_ &def (const char *name_, Func &&f, const Extra& ... extra) {
811811 cpp_function func (std::forward<Func>(f), name (name_), scope (*this ),
812812 sibling (getattr (*this , name_, none ())), extra...);
813813 // NB: allow overwriting here because cpp_function sets up a chain with the intention of
@@ -822,34 +822,34 @@ class module : public object {
822822
823823 .. code-block:: cpp
824824
825- py::module m("example", "pybind11 example plugin");
826- py::module m2 = m.def_submodule("sub", "A submodule of 'example'");
827- py::module m3 = m2.def_submodule("subsub", "A submodule of 'example.sub'");
825+ py::module_ m("example", "pybind11 example plugin");
826+ py::module_ m2 = m.def_submodule("sub", "A submodule of 'example'");
827+ py::module_ m3 = m2.def_submodule("subsub", "A submodule of 'example.sub'");
828828 \endrst */
829- module def_submodule (const char *name, const char *doc = nullptr ) {
829+ module_ def_submodule (const char *name, const char *doc = nullptr ) {
830830 std::string full_name = std::string (PyModule_GetName (m_ptr))
831831 + std::string (" ." ) + std::string (name);
832- auto result = reinterpret_borrow<module >(PyImport_AddModule (full_name.c_str ()));
832+ auto result = reinterpret_borrow<module_ >(PyImport_AddModule (full_name.c_str ()));
833833 if (doc && options::show_user_defined_docstrings ())
834834 result.attr (" __doc__" ) = pybind11::str (doc);
835835 attr (name) = result;
836836 return result;
837837 }
838838
839839 // / Import and return a module or throws `error_already_set`.
840- static module import (const char *name) {
840+ static module_ import (const char *name) {
841841 PyObject *obj = PyImport_ImportModule (name);
842842 if (!obj)
843843 throw error_already_set ();
844- return reinterpret_steal<module >(obj);
844+ return reinterpret_steal<module_ >(obj);
845845 }
846846
847847 // / Reload the module or throws `error_already_set`.
848848 void reload () {
849849 PyObject *obj = PyImport_ReloadModule (ptr ());
850850 if (!obj)
851851 throw error_already_set ();
852- *this = reinterpret_steal<module >(obj);
852+ *this = reinterpret_steal<module_ >(obj);
853853 }
854854
855855 // Adds an object to the module using the given name. Throws if an object with the given name
@@ -866,12 +866,16 @@ class module : public object {
866866 }
867867};
868868
869+ #if !defined(PYBIND11_CPP20)
870+ using module = module_;
871+ #endif
872+
869873// / \ingroup python_builtins
870874// / Return a dictionary representing the global variables in the current execution frame,
871875// / or ``__main__.__dict__`` if there is no frame (usually when the interpreter is embedded).
872876inline dict globals () {
873877 PyObject *p = PyEval_GetGlobals ();
874- return reinterpret_borrow<dict>(p ? p : module ::import (" __main__" ).attr (" __dict__" ).ptr ());
878+ return reinterpret_borrow<dict>(p ? p : module_ ::import (" __main__" ).attr (" __dict__" ).ptr ());
875879}
876880
877881NAMESPACE_BEGIN (detail)
@@ -1816,7 +1820,7 @@ PYBIND11_NOINLINE inline void print(tuple args, dict kwargs) {
18161820 file = kwargs[" file" ].cast <object>();
18171821 } else {
18181822 try {
1819- file = module ::import (" sys" ).attr (" stdout" );
1823+ file = module_ ::import (" sys" ).attr (" stdout" );
18201824 } catch (const error_already_set &) {
18211825 /* If print() is called from code that is executed as
18221826 part of garbage collection during interpreter shutdown,
0 commit comments