How to add a "type hint" for py::object? #4961
Unanswered
Yikai-Liao
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
If I bind a method with a py::object argument, of course I will get a typing.Any in the automatically generated stubs.
However, I want to restrict the type of it to
Union[int, float]
, because I will only manually cast this argument to int or float depending on another argument(a string).So, can I add some codes to meet this kind of requirement?
I know that I can just throw an error in my function if I fail to cast the argument to int or float. I'm just trying to make the interface exposed to the outside world more standardized (provide more valid type information)
Beta Was this translation helpful? Give feedback.
All reactions