Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve combomethod type hints #264

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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 @@ -52,6 +52,7 @@
include_package_data=True,
install_requires=[
"cached-property>=1.5.2,<2;python_version<'3.8'",
"typing_extensions",
"eth-hash>=0.3.1",
"eth-typing>=3.0.0",
"toolz>0.8.2;implementation_name=='pypy'",
Expand Down