How to add a "type hint" for py::object? #4961
              
                Unanswered
              
          
                  
                    
                      Yikai-Liao
                    
                  
                
                  asked this question in
                Q&A
              
            Replies: 1 comment
-
| 
         You could add a type caster for a thin wrapper around py::object or py::reference. The type caster should set its static name member to   | 
  
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
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