Fix module type hint (#5469)

* Fix module type hint

"module" is not a valid python value.
The correct type hint for a module object is "types.ModuleType" which has existed since at least Python 2.6

* Added module type hint test

* style: pre-commit fixes

* Remove doc function

* Fixed type hint

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
gentlegiantJGC 2024-12-31 03:53:30 +00:00 committed by GitHub
parent cf020a1de2
commit c5ed9d4b19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -1322,7 +1322,7 @@ PYBIND11_NAMESPACE_BEGIN(detail)
template <>
struct handle_type_name<module_> {
static constexpr auto name = const_name("module");
static constexpr auto name = const_name("types.ModuleType");
};
PYBIND11_NAMESPACE_END(detail)

View File

@ -81,6 +81,13 @@ def test_pydoc():
assert pydoc.text.docmodule(pybind11_tests)
def test_module_handle_type_name():
assert (
m.def_submodule.__doc__
== "def_submodule(arg0: types.ModuleType, arg1: str) -> types.ModuleType\n"
)
def test_duplicate_registration():
"""Registering two things with the same name"""