20 lines
592 B
Python
20 lines
592 B
Python
|
|
from typing import Callable, TypeVar, ParamSpec, Optional
|
|
|
|
P = ParamSpec('P') # captures the parameter types
|
|
R = TypeVar('R') # original return type
|
|
NewR = TypeVar('NewR') # new return type
|
|
|
|
def transform_return_type(func: Callable[P, R]) -> Callable[P, str]:
|
|
def wrapper(*args: P.args, **kwargs: P.kwargs) -> str:
|
|
# You'd do something meaningful here
|
|
result = func(*args, **kwargs)
|
|
return str(result) # Just an example transformation
|
|
return wrapper
|
|
|
|
@transform_return_type
|
|
def idk(test:Optional[str] = None)->int:
|
|
return 7
|
|
|
|
|
|
test = idk(test="hey") |