-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding typing to
process_receipts
via process_receipts_typed
. Ver…
…sion bump to v0.0.41 (#133) Major updates: - Adding `process_receipts_typed` that returns a dataclass typed event when given a transaction receipt. - Adding `combomethod_typed` that allows for combomethods that preserve types, and propagating the change throughout. - Similar to solution in eth-utils here: ethereum/eth-utils#264 - Renaming `get_typed_logs` to `get_logs_typed` for consistency. - Adding `BaseEventArgs` and frozen dataclass attribute for arg subclassing. This also ensures the `arg` field exists in all event types.
- Loading branch information
Showing
47 changed files
with
258 additions
and
440 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
"""Export all types from generated files. | ||
DO NOT EDIT. This file was generated by pypechain v0.0.40. | ||
DO NOT EDIT. This file was generated by pypechain v0.0.41. | ||
See documentation at https://github.com/delvtech/pypechain """ | ||
|
||
from .ExampleContract import ExampleContract |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
pypechain == 0.0.40 | ||
pypechain == 0.0.41 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
"""Core pypechain functions used by generated files""" | ||
|
||
from .base_event import BaseEvent | ||
from .base_event import BaseEvent, BaseEventArgs | ||
from .combomethod_typed import combomethod_typed | ||
from .error import ErrorInfo, ErrorParams | ||
from .utilities import dataclass_to_tuple, get_abi_input_types, rename_returned_types, tuple_to_dataclass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""A typed version of combomethod from eth_utils.""" | ||
|
||
import functools | ||
from typing import Any, Callable, Concatenate, Generic, Optional, ParamSpec, Type, TypeVar | ||
|
||
# TODO remove this file once https://github.com/ethereum/eth-utils/pull/264 gets merged | ||
|
||
# We use generics to define the structure of the wrapped method | ||
# Here, `T` is the `self` or `cls` object, `P` is the parameter of the wrapped function, and | ||
# `R` is the return type | ||
|
||
T = TypeVar("T") | ||
P = ParamSpec("P") | ||
R = TypeVar("R") | ||
|
||
|
||
# We define the generic that attaches to the function we're decorating | ||
# so here, P and R are the types of the parameters and return of the decorated function | ||
class combomethod_typed(Generic[P, R]): # pylint: disable=invalid-name | ||
"""A typed version of combomethod from eth_utils.""" | ||
|
||
# The callable `Any` takes place of the obj or class | ||
method: Callable[Concatenate[Any, P], R] | ||
|
||
# The method passed in has a spot for obj or class in `Any` | ||
def __init__(self, method: Callable[Concatenate[Any, P], R]) -> None: | ||
self.method = method | ||
|
||
# The getter allows for logic to call either cls or obj method | ||
# with the original type decorators in the output wrapper function | ||
def __get__(self, obj: Optional[T] = None, objtype: Optional[Type[T]] = None) -> Callable[P, R]: | ||
# The _wrapper function is unchanged from eth-utils | ||
@functools.wraps(self.method) | ||
def _wrapper(*args: P.args, **kwargs: P.kwargs) -> R: | ||
if obj is not None: | ||
return self.method(obj, *args, **kwargs) | ||
return self.method(objtype, *args, **kwargs) | ||
|
||
return _wrapper |
Oops, something went wrong.