Skip to content

Instantly share code, notes, and snippets.

@CodeByAidan
Created July 30, 2024 13:46
Show Gist options
  • Save CodeByAidan/20ff40a9d6a71f9396ca9d708c923034 to your computer and use it in GitHub Desktop.
Save CodeByAidan/20ff40a9d6a71f9396ca9d708c923034 to your computer and use it in GitHub Desktop.
functools.wraps return type decorator template
from typing import Callable, Generic, ParamSpec, Protocol, TypeVar, overload
_PD = ParamSpec('_PD')
_PF = ParamSpec('_PF')
_RD = TypeVar('_RD')
_RF = TypeVar('_RF')
# from functools import _Wrapped as _W
class _W(Generic[_PF, _RF, _PD, _RD]):
...
class _DecoOrFab(Protocol[_PD, _RD]):
@overload
def __call__(self, f: Callable[_PF, _RF]) -> _W[_PF, _RF, ..., _RD]: ...
@overload
def __call__(self, **kwargs) -> _W[_PD, _RD, ..., ...]: ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment