-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix module type hint #5469
Fix module type hint #5469
Conversation
"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
@@ -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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a test? I think it's really simple:
Add in tests/test_modules.py:
def test_module_handle_type_name():
assert m.def_submodule.__doc__ == "TODO"
or possibly
def test_module_handle_type_name(doc):
assert doc(m.def_submodule) == "TODO"
I'd try the __doc__
version first because it's stricter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added this test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Description
"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
Suggested changelog entry: