@@ -852,12 +852,12 @@ class cpp_function : public function {
852
852
};
853
853
854
854
// / Wrapper for Python extension modules
855
- class module : public object {
855
+ class module_ : public object {
856
856
public:
857
- PYBIND11_OBJECT_DEFAULT (module , object, PyModule_Check)
857
+ PYBIND11_OBJECT_DEFAULT (module_ , object, PyModule_Check)
858
858
859
859
// / Create a new top-level Python module with the given name and docstring
860
- explicit module (const char *name, const char *doc = nullptr ) {
860
+ explicit module_ (const char *name, const char *doc = nullptr ) {
861
861
if (!options::show_user_defined_docstrings ()) doc = nullptr ;
862
862
#if PY_MAJOR_VERSION >= 3
863
863
auto *def = new PyModuleDef ();
@@ -871,7 +871,7 @@ class module : public object {
871
871
m_ptr = Py_InitModule3 (name, nullptr , doc);
872
872
#endif
873
873
if (m_ptr == nullptr )
874
- pybind11_fail (" Internal error in module::module ()" );
874
+ pybind11_fail (" Internal error in module_::module_ ()" );
875
875
inc_ref ();
876
876
}
877
877
@@ -881,7 +881,7 @@ class module : public object {
881
881
details on the ``Extra&& ... extra`` argument, see section :ref:`extras`.
882
882
\endrst */
883
883
template <typename Func, typename ... Extra>
884
- module &def (const char *name_, Func &&f, const Extra& ... extra) {
884
+ module_ &def (const char *name_, Func &&f, const Extra& ... extra) {
885
885
cpp_function func (std::forward<Func>(f), name (name_), scope (*this ),
886
886
sibling (getattr (*this , name_, none ())), extra...);
887
887
// NB: allow overwriting here because cpp_function sets up a chain with the intention of
@@ -900,30 +900,30 @@ class module : public object {
900
900
py::module m2 = m.def_submodule("sub", "A submodule of 'example'");
901
901
py::module m3 = m2.def_submodule("subsub", "A submodule of 'example.sub'");
902
902
\endrst */
903
- module def_submodule (const char *name, const char *doc = nullptr ) {
903
+ module_ def_submodule (const char *name, const char *doc = nullptr ) {
904
904
std::string full_name = std::string (PyModule_GetName (m_ptr))
905
905
+ std::string (" ." ) + std::string (name);
906
- auto result = reinterpret_borrow<module >(PyImport_AddModule (full_name.c_str ()));
906
+ auto result = reinterpret_borrow<module_ >(PyImport_AddModule (full_name.c_str ()));
907
907
if (doc && options::show_user_defined_docstrings ())
908
908
result.attr (" __doc__" ) = pybind11::str (doc);
909
909
attr (name) = result;
910
910
return result;
911
911
}
912
912
913
913
// / Import and return a module or throws `error_already_set`.
914
- static module import (const char *name) {
914
+ static module_ import (const char *name) {
915
915
PyObject *obj = PyImport_ImportModule (name);
916
916
if (!obj)
917
917
throw error_already_set ();
918
- return reinterpret_steal<module >(obj);
918
+ return reinterpret_steal<module_ >(obj);
919
919
}
920
920
921
921
// / Reload the module or throws `error_already_set`.
922
922
void reload () {
923
923
PyObject *obj = PyImport_ReloadModule (ptr ());
924
924
if (!obj)
925
925
throw error_already_set ();
926
- *this = reinterpret_steal<module >(obj);
926
+ *this = reinterpret_steal<module_ >(obj);
927
927
}
928
928
929
929
// Adds an object to the module using the given name. Throws if an object with the given name
@@ -940,6 +940,8 @@ class module : public object {
940
940
}
941
941
};
942
942
943
+ using module = module_;
944
+
943
945
// / \ingroup python_builtins
944
946
// / Return a dictionary representing the global variables in the current execution frame,
945
947
// / or ``__main__.__dict__`` if there is no frame (usually when the interpreter is embedded).
0 commit comments