Skip to content

Commit c5ed9d4

Browse files
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>
1 parent cf020a1 commit c5ed9d4

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

include/pybind11/pybind11.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ PYBIND11_NAMESPACE_BEGIN(detail)
13221322

13231323
template <>
13241324
struct handle_type_name<module_> {
1325-
static constexpr auto name = const_name("module");
1325+
static constexpr auto name = const_name("types.ModuleType");
13261326
};
13271327

13281328
PYBIND11_NAMESPACE_END(detail)

tests/test_modules.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ def test_pydoc():
8181
assert pydoc.text.docmodule(pybind11_tests)
8282

8383

84+
def test_module_handle_type_name():
85+
assert (
86+
m.def_submodule.__doc__
87+
== "def_submodule(arg0: types.ModuleType, arg1: str) -> types.ModuleType\n"
88+
)
89+
90+
8491
def test_duplicate_registration():
8592
"""Registering two things with the same name"""
8693

0 commit comments

Comments
 (0)