From f828826a2437a97117f850c94e0d9bbbc54e8823 Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Mon, 16 Dec 2024 10:45:57 +0000 Subject: [PATCH 1/5] 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 --- include/pybind11/pybind11.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 7fc7dbf723..4387c2754b 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1322,7 +1322,7 @@ PYBIND11_NAMESPACE_BEGIN(detail) template <> struct handle_type_name { - static constexpr auto name = const_name("module"); + static constexpr auto name = const_name("types.ModuleType"); }; PYBIND11_NAMESPACE_END(detail) From 29679ebaccf4bac3047f5b8d0839a51dc6ebf415 Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Mon, 30 Dec 2024 17:13:06 +0000 Subject: [PATCH 2/5] Added module type hint test --- tests/test_modules.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_modules.py b/tests/test_modules.py index 436271a701..1b6f101c93 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -81,6 +81,10 @@ def test_pydoc(): assert pydoc.text.docmodule(pybind11_tests) +def test_module_handle_type_name(): + assert doc(m.def_submodule) == "def_submodule(arg0: module, arg1: str) -> types.ModuleType" + + def test_duplicate_registration(): """Registering two things with the same name""" From 7b25edb568d7ec893c3acde3d85ef5a6ccb67301 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 30 Dec 2024 17:13:30 +0000 Subject: [PATCH 3/5] style: pre-commit fixes --- tests/test_modules.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_modules.py b/tests/test_modules.py index 1b6f101c93..23ce4c507e 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -82,7 +82,10 @@ def test_pydoc(): def test_module_handle_type_name(): - assert doc(m.def_submodule) == "def_submodule(arg0: module, arg1: str) -> types.ModuleType" + assert ( + doc(m.def_submodule) + == "def_submodule(arg0: module, arg1: str) -> types.ModuleType" + ) def test_duplicate_registration(): From edd479c9096044af33c69b3fef467133b923617e Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Mon, 30 Dec 2024 17:17:03 +0000 Subject: [PATCH 4/5] Remove doc function --- tests/test_modules.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_modules.py b/tests/test_modules.py index 23ce4c507e..21048053a8 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -83,8 +83,8 @@ def test_pydoc(): def test_module_handle_type_name(): assert ( - doc(m.def_submodule) - == "def_submodule(arg0: module, arg1: str) -> types.ModuleType" + m.def_submodule.__doc__ + == "def_submodule(arg0: module, arg1: str) -> types.ModuleType\n" ) From 8b2372ea020a4a0eaf4f4abcf8ef3c8f3a553435 Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Mon, 30 Dec 2024 17:29:18 +0000 Subject: [PATCH 5/5] Fixed type hint --- tests/test_modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_modules.py b/tests/test_modules.py index 21048053a8..ad898be89a 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -84,7 +84,7 @@ def test_pydoc(): def test_module_handle_type_name(): assert ( m.def_submodule.__doc__ - == "def_submodule(arg0: module, arg1: str) -> types.ModuleType\n" + == "def_submodule(arg0: types.ModuleType, arg1: str) -> types.ModuleType\n" )