You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For osandov/drgn#364, I'd like to be able to define a decorator that modifies the parameter types of the functions it wraps, but also preserves keywords.
For a toy example, imagine a decorator that wraps a function taking an int as the first parameter (possibly as a keyword argument) so that it can also take a str that is automatically converted to an int. I can do this manually with overloads:
But this is tedious and error-prone if you have a lot of functions using the decorator. ParamSpec almost gets me what I want, but it doesn't preserve keywords:
For osandov/drgn#364, I'd like to be able to define a decorator that modifies the parameter types of the functions it wraps, but also preserves keywords.
For a toy example, imagine a decorator that wraps a function taking an
int
as the first parameter (possibly as a keyword argument) so that it can also take astr
that is automatically converted to anint
. I can do this manually with overloads:But this is tedious and error-prone if you have a lot of functions using the decorator.
ParamSpec
almost gets me what I want, but it doesn't preserve keywords:This seems somewhat related to #1273, although I want to specify the transformation by parameter, not by input type.
P.S. I used
Callable
here, but my real use cases need aProtocol
with__call__
because they have more complicated signatures.The text was updated successfully, but these errors were encountered: