is there anyone knows how to overload hint like the default overload.decorator
do?
I have a custom working overload decorator, but cannot hint correctly.
* the way to custom overload decorator for example
The reason behind doing this is because of :
- 1: Default
overload.decorator
is only for decoration - 2: Alternative ways like
multipledispatch.dispatch
are not from standard library
For example, in vscode, the default @overload will hint like below
from typing import overload
class Foo :
@overload
def bar( self , value : int ) -> int : ...
@overload
def bar( self , value : str ) -> str : ...
The custom overload decorator, however, will only display the last loaded method.
def custom_overload( * types ) :
# logic to resolve callable
...
class Foo :
@custom_overload( int )
def bar( self , value : int ) -> int : ...
@custom_overload( str )
def bar( self , value : str ) -> str : ...
How can I hint the decorated callable like the default overload.decorator
do.
Is it related to this?
How to document Python functions with overload/dispatch decorators?
Thank you for your advises.