@@ -868,19 +868,28 @@ class cpp_function : public function {
868
868
}
869
869
};
870
870
871
- // / Wrapper for Python extension modules
871
+ // / Wrapper for Python modules
872
872
class module_ : public object {
873
873
public:
874
874
PYBIND11_OBJECT_DEFAULT (module_, object, PyModule_Check)
875
875
876
876
// / Create a new top-level Python module with the given name and docstring
877
- PYBIND11_DEPRECATED (" Use PYBIND11_MODULE, module_::def_submodule, or module_::import instead" )
878
877
explicit module_ (const char *name, const char *doc = nullptr ) {
879
- #if PY_MAJOR_VERSION >= 3
880
- *this = create_extension_module (name, doc, new PyModuleDef ());
878
+ #if defined(PYPY_VERSION)
879
+ m_ptr = PyModule_New (const_cast <char *>(name));
880
+ #else
881
+ m_ptr = PyModule_New (name);
882
+ #endif
883
+ if (m_ptr == nullptr )
884
+ pybind11_fail (" Internal error in module_::module_()" );
885
+ if (doc && options::show_user_defined_docstrings ()) {
886
+ #if PY_MAJOR_VERSION >= 3 && !defined(PYPY_VERSION)
887
+ if (PyModule_SetDocString (m_ptr, doc) != 0 )
888
+ throw error_already_set ();
881
889
#else
882
- * this = create_extension_module (name, doc, nullptr );
890
+ setattr (m_ptr, " __doc__ " , PYBIND11_STR_TYPE (doc) );
883
891
#endif
892
+ }
884
893
}
885
894
886
895
/* * \rst
0 commit comments