From 64c1f77b92072e31d9d5c8e7c38782291af69bbb Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 29 Jul 2025 04:01:51 +0000 Subject: [PATCH 1/2] chore: bump compiler version --- .github/workflows/build.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 0b17577e6f..2d27727e2f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -92,7 +92,7 @@ jobs: run: | git config --local user.name "github-actions[bot]" git config --local user.email "github-actions[bot]@users.noreply.github.com" - git add . + git add git commit -m "chore: compile to C for Linux x64 with mypyc" git push @@ -178,7 +178,7 @@ jobs: run: | git config --local user.name "github-actions[bot]" git config --local user.email "github-actions[bot]@users.noreply.github.com" - git add . + git add git commit -m "chore: compile to C for macOS with mypyc" git push @@ -265,6 +265,6 @@ jobs: run: | git config --local user.name "github-actions[bot]" git config --local user.email "github-actions[bot]@users.noreply.github.com" - git add . + git add git commit -m "chore: compile to C for Windows AMD64 with mypyc" git push From 17cdeb56bc8db8d29970264ac10fa0f6af58c73b Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 29 Jul 2025 03:27:05 +0000 Subject: [PATCH 2/2] chore: bump compiler version --- dank_mids/_eth_utils.py | 3 ++- dank_mids/_web3/abi.py | 16 ++++++++++------ dank_mids/_web3/formatters.py | 6 +++--- dank_mids/brownie_patch/call.py | 10 +++++----- dank_mids/helpers/_codec.py | 8 ++++---- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/dank_mids/_eth_utils.py b/dank_mids/_eth_utils.py index 3a290f56d4..ddb5710f36 100644 --- a/dank_mids/_eth_utils.py +++ b/dank_mids/_eth_utils.py @@ -1,3 +1,4 @@ +# mypy: disable-error-code="attr-defined" """eth_utils uses a decorator to ensure certain functions are called with proper args. This is helpful for development but adds unnecessary overhead for production use. @@ -96,7 +97,7 @@ def to_hex( ) elif isinstance(primitive, int): - return hex(primitive) + return hex(primitive) # type: ignore [return-value] raise TypeError( f"Unsupported type: '{repr(type(primitive))}'. Must be one of: bool, str, " diff --git a/dank_mids/_web3/abi.py b/dank_mids/_web3/abi.py index 570a3a5b85..fce8a3cdf3 100644 --- a/dank_mids/_web3/abi.py +++ b/dank_mids/_web3/abi.py @@ -1,14 +1,11 @@ import typing -from typing import Any, Callable, Dict, Final, Iterator, List, Tuple, TypeVar, final +from typing import Any, Callable, Dict, Final, List, Optional, Tuple, final from eth_abi.grammar import parse from eth_typing import TypeStr from web3._utils import abi -_T = TypeVar("_T") - - Normalizer = Callable[[TypeStr, Any], Tuple[TypeStr, Any]] MapperKey = Tuple[Tuple[Normalizer, ...], Tuple[TypeStr, ...]] DataTreeFunc = Callable[[TypeStr, Any], Tuple[TypeStr, Any]] @@ -28,11 +25,18 @@ class Formatter: def __init__( self, normalizers: Tuple[Normalizer, ...], - types: Tuple[TypeStr, ...], + types: Tuple[Optional[TypeStr], ...], ): # TODO: vendor ABITypedData and cache some stuff from web3py self.normalizers: Final = tuple(get_data_tree_map(n) for n in normalizers) - self.types: Final = [parse(t) if isinstance(t, TypeStr) else t for t in types] + self.types: Final = [] + + t: Optional[TypeStr] + for t in types: + if isinstance(t, TypeStr): + self.types.append(parse(t)) + else: + self.types.append(t) def __call__(self, data: Any) -> List[Any]: # 1. Decorating the data tree with types diff --git a/dank_mids/_web3/formatters.py b/dank_mids/_web3/formatters.py index 0092eb8866..4dd947a43f 100644 --- a/dank_mids/_web3/formatters.py +++ b/dank_mids/_web3/formatters.py @@ -1,8 +1,8 @@ from typing import Any, Callable, Dict, Final, Iterator, List, Sequence, Tuple, TypeVar, Union from eth_typing import TypeStr -from faster_eth_utils.curried import apply_formatter_at_index -from faster_eth_utils.toolz import compose +from faster_eth_utils.curried import apply_formatter_at_index # type: ignore [attr-defined] +from faster_eth_utils.toolz import compose # type: ignore [attr-defined] from web3._utils.method_formatters import ( ERROR_FORMATTERS, METHOD_NORMALIZERS, @@ -39,7 +39,7 @@ def abi_request_formatters( ABI_REQUEST_FORMATTERS: Final[Formatters] = dict( - abi_request_formatters(STANDARD_NORMALIZERS, RPC_ABIS) + abi_request_formatters(STANDARD_NORMALIZERS, RPC_ABIS) # type: ignore [arg-type] ) REQUEST_FORMATTER_MAPS: Final = ( diff --git a/dank_mids/brownie_patch/call.py b/dank_mids/brownie_patch/call.py index ab0d13e673..564a70e595 100644 --- a/dank_mids/brownie_patch/call.py +++ b/dank_mids/brownie_patch/call.py @@ -246,15 +246,15 @@ async def decode_output(call: ContractCall, data: bytes) -> Any: async def _request_data_no_args(call: ContractCall) -> HexStr: - return call.signature + return call.signature # type: ignore [no-any-return] # These methods were renamed in eth-abi 4.0.0 __eth_abi_encode: Final[Callable[[TypeStrs, List[Any]], bytes]] = ( - eth_abi.encode if hasattr(eth_abi, "encode") else eth_abi.encode_abi + eth_abi.encode if hasattr(eth_abi, "encode") else eth_abi.encode_abi # type: ignore [attr-defined] ) __eth_abi_decode: Final[Callable[[TypeStrs, hexbytes.HexBytes], Tuple[Any, ...]]] = ( - eth_abi.decode if hasattr(eth_abi, "decode") else eth_abi.decode_abi + eth_abi.decode if hasattr(eth_abi, "decode") else eth_abi.decode_abi # type: ignore [attr-defined] ) @@ -262,7 +262,7 @@ def __encode_input(abi: AbiDict, signature: str, *args: Any) -> Union[HexStr, Ex try: data = format_input_but_cache_checksums(abi, args) types_list = get_type_strings(abi["inputs"]) - return signature + __eth_abi_encode(types_list, data).hex() + return signature + __eth_abi_encode(types_list, data).hex() # type: ignore [return-value] except Exception as e: return e @@ -297,7 +297,7 @@ def __validate_output(abi: AbiDict, hexstr: BytesLike) -> None: try: selector = HexBytes(hexstr)[:4].hex() if selector == "0x08c379a0": - revert_str = eth_abi.decode_abi(["string"], HexBytes(hexstr)[4:])[0] + revert_str = eth_abi.decode_abi(["string"], HexBytes(hexstr)[4:])[0] # type: ignore [attr-defined] raise Revert(f"Call reverted: {revert_str}") elif selector == "0x4e487b71": error_code = int(HexBytes(hexstr)[4:].hex(), 16) diff --git a/dank_mids/helpers/_codec.py b/dank_mids/helpers/_codec.py index 1db8512ba2..fed3143ebd 100644 --- a/dank_mids/helpers/_codec.py +++ b/dank_mids/helpers/_codec.py @@ -163,7 +163,7 @@ def _encode_hook(obj: Encodable) -> RpcThing: if isinstance(obj, HexBytes): return obj.hex() # type: ignore [return-value] elif isinstance(obj, Address): - return str(obj) + return str(obj) # type: ignore [return-value] else: raise ValueError(*e.args, obj, type(obj)) from e @@ -174,7 +174,7 @@ def _rudimentary_encode_dict_value(value: int) -> HexStr: ... def _rudimentary_encode_dict_value(value: __T) -> __T: ... def _rudimentary_encode_dict_value(value: Union[int, __T]) -> Union[HexStr, __T]: # I dont think this needs to be robust, time will tell - return hex(value) if isinstance(value, int) else value + return hex(value) if isinstance(value, int) else value # type: ignore [return-value] encode: Final = Encoder(enc_hook=_encode_hook).encode @@ -200,7 +200,7 @@ def _rudimentary_encode_dict_value(value: Union[int, __T]) -> Union[HexStr, __T] "(bool,(address,bytes)[])" ) _array_encoder: Final[DynamicArrayEncoder] = _mcall_encoder.encoders[-1] # type: ignore [attr-defined] -_item_encoder: Final[TupleEncoder] = _array_encoder.item_encoder +_item_encoder: Final[TupleEncoder] = _array_encoder.item_encoder # type: ignore [assignment] # We don't need to follow the validation code from eth-abi since we guarantee the input types _mcall_encoder.validate_value = _array_encoder.validate_value = _item_encoder.validate_value = lambda *_: ... # type: ignore [attr-defined, method-assign] @@ -252,7 +252,7 @@ def mcall_encode(data: Iterable[MulticallChunk]) -> bytes: def mcall_decode(data: "types.PartialResponse") -> Union[List[bytes], Exception]: try: - decoded = _mcall_decoder(ContextFramesBytesIO(data.decode_result("eth_call")))[2] # type: ignore [arg-type] + decoded = _mcall_decoder(ContextFramesBytesIO(data.decode_result("eth_call")))[2] # type: ignore [arg-type, no-untyped-call] except Exception as e: if PartialResponse is None: __import_from_types()