Open
Description
Currently wrapping functions with these class based decorators will obliterate type information. With the introduction of Paramspec
in python 3.10 and the backports library typing_extensions
it should be possible (using Generic
) to preserve this information.
The code for this looks like this
from typing_extensions import ParamSpec
from typing import Callable, Generic, TypeVar
return_value = TypeVar("return_value")
parameters = ParamSpec("parameters")
class FooDecorator(Generic[parameters, return_value]):
def __init__(self,func: Callable[parameters, return_value]):
self.func = func
def __call__(self,*args:parameters.args, **kwargs:parameters.kwargs)-> return_value:
return self.func(*args,**kwargs)
This would currently be blocked by a bug in the typing backport (python/typing#817), but is soon to resolved. I would be happy to create a PR for this once the bug is resolved.
Metadata
Metadata
Assignees
Labels
No labels