I'd like to forward the call of a method to another method, and have the second method's type hints show up in the first method. Probably easier to demonstrate.
When an instance of the class below is called, it looks up the method with the name "num_to_str", calls it, and returns the result. I'd like the type hints for "num_to_str" to show up when you call the object.
class MyClass:
call_func_name = 'num_to_str'
def num_to_str(self, num: int) -> str:
return str(num)
def __call__(self, *args, **kwds):
return getattr(self, 'call_func_name')(*args, **kwds)
mc = MyClass()
mc(<tab>. # want type hints for num_to_str to show up
I'm using the method name and looking up via getattr rather than just setting __call__ = num_to_start
so that if the num_to_str function is changed (for example, overridden in a subclass), it uses the correct/updated function.
Using Pylance/Pyright in VS Code for autocompletion/type hints.