Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions eth_utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,34 @@
Any,
Callable,
Dict,
Optional,
Generic,
Type,
TypeVar,
Union,
)

from typing_extensions import (
Concatenate,
ParamSpec,
)

from .types import (
is_text,
)

T = TypeVar("T")
P = ParamSpec("P")


class combomethod:
def __init__(self, method: Callable[..., Any]) -> None:
class combomethod(Generic[P, T]):
def __init__(self, method: Callable[Concatenate[Any, P], T]) -> None:
self.method = method

def __get__(
self, obj: Optional[T] = None, objtype: Optional[Type[T]] = None
) -> Callable[..., Any]:
self, obj: object = None, objtype: Union[type, None] = None
) -> Callable[P, T]:
@functools.wraps(self.method)
def _wrapper(*args: Any, **kwargs: Any) -> Any:
def _wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
if obj is not None:
return self.method(obj, *args, **kwargs)
else:
Expand Down
1 change: 1 addition & 0 deletions newsfragments/236.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve type hints for decorator combomethod.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
url="https://github.com/ethereum/eth-utils",
include_package_data=True,
install_requires=[
"typing_extensions",
"eth-hash>=0.3.1",
"eth-typing>=5.0.0",
"toolz>0.8.2;implementation_name=='pypy'",
Expand Down