From ca3e490a7e8bc65599964fba64940474b4ae69ff Mon Sep 17 00:00:00 2001 From: Alex Harris Date: Tue, 7 Oct 2025 22:32:49 +0100 Subject: [PATCH 1/8] fix: Made function params Optional, as None is the default input --- web3/_utils/module.py | 2 +- web3/main.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/web3/_utils/module.py b/web3/_utils/module.py index 63fc151232..f621586aa5 100644 --- a/web3/_utils/module.py +++ b/web3/_utils/module.py @@ -42,7 +42,7 @@ def _validate_init_params_and_return_if_found(module_class: Any) -> List[str]: def attach_modules( parent_module: Union["BaseWeb3", "Module"], - module_definitions: Dict[str, Any], + module_definitions: Optional[Dict[str, Any]], w3: Optional[Union["BaseWeb3", "Module"]] = None, ) -> None: for module_name, module_info in module_definitions.items(): diff --git a/web3/main.py b/web3/main.py index b388f95b16..c118c0d5e1 100644 --- a/web3/main.py +++ b/web3/main.py @@ -210,28 +210,28 @@ def middleware_onion(self) -> MiddlewareOnion: @staticmethod @wraps(to_bytes) def to_bytes( - primitive: Primitives = None, hexstr: HexStr = None, text: str = None + primitive: Primitives = None, hexstr: HexStr = None, text: Optional[str] = None ) -> bytes: return to_bytes(primitive, hexstr, text) @staticmethod @wraps(to_int) def to_int( - primitive: Primitives = None, hexstr: HexStr = None, text: str = None + primitive: Primitives = None, hexstr: HexStr = None, text: Optional[str] = None ) -> int: return to_int(primitive, hexstr, text) @staticmethod @wraps(to_hex) def to_hex( - primitive: Primitives = None, hexstr: HexStr = None, text: str = None + primitive: Primitives = None, hexstr: HexStr = None, text: Optional[str] = None ) -> HexStr: return to_hex(primitive, hexstr, text) @staticmethod @wraps(to_text) def to_text( - primitive: Primitives = None, hexstr: HexStr = None, text: str = None + primitive: Primitives = None, hexstr: HexStr = None, text: Optional[str] = None ) -> str: return to_text(primitive, hexstr, text) From 816e7214c696c9e066e263f7fa5dde9e7c9edbea Mon Sep 17 00:00:00 2001 From: Alex Harris Date: Tue, 7 Oct 2025 22:58:23 +0100 Subject: [PATCH 2/8] feat: Made AsyncWeb3 class Generic to fix type errors when importing Web3 --- ens/async_ens.py | 6 +- ens/base_ens.py | 2 +- ens/utils.py | 3 +- .../contracts/test_contract_call_interface.py | 10 +- tests/core/utilities/test_abi.py | 6 +- tests/core/web3-module/test_conversions.py | 2 +- web3/_utils/abi.py | 14 +- web3/_utils/async_transactions.py | 21 +- web3/_utils/batching.py | 8 +- web3/_utils/caching/caching_utils.py | 4 +- web3/_utils/contracts.py | 10 +- web3/_utils/ens.py | 2 +- web3/_utils/events.py | 2 +- web3/_utils/module_testing/eth_module.py | 258 +++++++++--------- .../go_ethereum_admin_module.py | 13 +- .../go_ethereum_debug_module.py | 9 +- .../go_ethereum_txpool_module.py | 9 +- web3/_utils/module_testing/net_module.py | 7 +- .../persistent_connection_provider.py | 46 ++-- web3/_utils/module_testing/utils.py | 13 +- web3/_utils/module_testing/web3_module.py | 32 ++- web3/_utils/normalizers.py | 6 +- web3/_utils/transactions.py | 3 +- web3/contract/async_contract.py | 26 +- web3/contract/base_contract.py | 23 +- web3/contract/utils.py | 14 +- web3/eth/async_eth.py | 2 +- web3/gas_strategies/time_based.py | 2 +- web3/main.py | 17 +- web3/manager.py | 17 +- web3/middleware/__init__.py | 2 +- web3/middleware/base.py | 10 +- web3/middleware/buffered_gas_estimate.py | 2 +- web3/middleware/filter.py | 19 +- web3/middleware/formatting.py | 8 +- web3/middleware/gas_price_strategy.py | 2 +- web3/middleware/names.py | 8 +- web3/middleware/signing.py | 6 +- web3/middleware/stalecheck.py | 4 +- web3/middleware/validation.py | 4 +- web3/module.py | 6 +- web3/providers/async_base.py | 4 +- web3/providers/eth_tester/defaults.py | 4 +- web3/providers/eth_tester/main.py | 2 +- web3/providers/eth_tester/middleware.py | 4 +- web3/providers/persistent/persistent.py | 8 +- .../persistent/persistent_connection.py | 2 +- .../persistent/subscription_manager.py | 2 +- web3/providers/persistent/utils.py | 2 +- web3/tools/benchmark/main.py | 2 +- web3/types.py | 2 +- web3/utils/subscriptions.py | 2 +- 52 files changed, 366 insertions(+), 326 deletions(-) diff --git a/ens/async_ens.py b/ens/async_ens.py index f4da906ae3..9cf003805f 100644 --- a/ens/async_ens.py +++ b/ens/async_ens.py @@ -96,7 +96,7 @@ class AsyncENS(BaseENS): """ # mypy types - w3: "AsyncWeb3" + w3: "AsyncWeb3[Any]" def __init__( self, @@ -123,7 +123,9 @@ def __init__( ) @classmethod - def from_web3(cls, w3: "AsyncWeb3", addr: ChecksumAddress = None) -> "AsyncENS": + def from_web3( + cls, w3: "AsyncWeb3[Any]", addr: ChecksumAddress = None + ) -> "AsyncENS": """ Generate an AsyncENS instance with web3 diff --git a/ens/base_ens.py b/ens/base_ens.py index 4f1534d994..19efab94d7 100644 --- a/ens/base_ens.py +++ b/ens/base_ens.py @@ -38,7 +38,7 @@ class BaseENS: - w3: Union["AsyncWeb3", "Web3"] = None + w3: Union["AsyncWeb3[Any]", "Web3"] = None ens: Union["Contract", "AsyncContract"] = None _resolver_contract: Union[Type["Contract"], Type["AsyncContract"]] = None _reverse_resolver_contract: Union[Type["Contract"], Type["AsyncContract"]] = None diff --git a/ens/utils.py b/ens/utils.py index 824a5bd0f3..4e497595ac 100644 --- a/ens/utils.py +++ b/ens/utils.py @@ -302,7 +302,7 @@ def is_valid_ens_name(ens_name: str) -> bool: def init_async_web3( provider: "AsyncBaseProvider" = None, middleware: Optional[Sequence[Tuple["Middleware", str]]] = (), -) -> "AsyncWeb3": +) -> "AsyncWeb3[Any]": from web3 import ( AsyncWeb3 as AsyncWeb3Main, ) @@ -327,6 +327,7 @@ def init_async_web3( ) ) + async_w3: "AsyncWeb3[Any]" if provider is default: async_w3 = AsyncWeb3Main( middleware=middleware, ens=None, modules={"eth": (AsyncEthMain)} diff --git a/tests/core/contracts/test_contract_call_interface.py b/tests/core/contracts/test_contract_call_interface.py index 5f364f142f..7496a8c265 100644 --- a/tests/core/contracts/test_contract_call_interface.py +++ b/tests/core/contracts/test_contract_call_interface.py @@ -238,8 +238,8 @@ def test_call_get_byte_array_non_strict(non_strict_arrays_contract, call): "args,expected", [ ([b"1"], [b"1"]), - (["0xDe"], [b"\xDe"]), - (["0xDe", "0xDe"], [b"\xDe", b"\xDe"]), + (["0xDe"], [b"\xde"]), + (["0xDe", "0xDe"], [b"\xde", b"\xde"]), ], ) def test_set_byte_array(arrays_contract, call, transact, args, expected): @@ -257,8 +257,8 @@ def test_set_byte_array(arrays_contract, call, transact, args, expected): "args,expected", [ ([b"1"], [b"1"]), - (["0xDe"], [b"\xDe"]), - (["0xDe", "0xDe"], [b"\xDe", b"\xDe"]), + (["0xDe"], [b"\xde"]), + (["0xDe", "0xDe"], [b"\xde", b"\xde"]), ], ) def test_set_byte_array_non_strict( @@ -1503,7 +1503,7 @@ async def test_async_set_byte_array_non_strict( @pytest.mark.asyncio -@pytest.mark.parametrize("args,expected", [([b"1"], [b"1"]), (["0xDe"], [b"\xDe"])]) +@pytest.mark.parametrize("args,expected", [([b"1"], [b"1"]), (["0xDe"], [b"\xde"])]) async def test_async_set_byte_array_strict_by_default( async_arrays_contract, async_call, async_transact, args, expected ): diff --git a/tests/core/utilities/test_abi.py b/tests/core/utilities/test_abi.py index baebbec247..b7b0b39b05 100644 --- a/tests/core/utilities/test_abi.py +++ b/tests/core/utilities/test_abi.py @@ -249,8 +249,8 @@ def test_get_tuple_type_str_parts( [ ( ["bool[2]", "bytes"], - [[True, False], b"\x00\xFF"], - [("bool[2]", [("bool", True), ("bool", False)]), ("bytes", b"\x00\xFF")], + [[True, False], b"\x00\xff"], + [("bool[2]", [("bool", True), ("bool", False)]), ("bytes", b"\x00\xff")], ), ( ["uint256[]"], @@ -337,7 +337,7 @@ def test_map_abi_data( @pytest.mark.parametrize("arg", (6, 7, 9, 12, 20, 30)) def test_exact_length_bytes_encoder_raises_on_non_multiples_of_8_bit_size( - arg: Tuple[int, ...] + arg: Tuple[int, ...], ) -> None: with pytest.raises(Web3ValueError, match="multiple of 8"): _ = ExactLengthBytesEncoder(None, data_byte_size=2, value_bit_size=arg) diff --git a/tests/core/web3-module/test_conversions.py b/tests/core/web3-module/test_conversions.py index ff1b75025b..1fe13630fe 100644 --- a/tests/core/web3-module/test_conversions.py +++ b/tests/core/web3-module/test_conversions.py @@ -159,7 +159,7 @@ def test_to_int_hexstr(val, expected): (b"\x01", "0x01"), (b"\x10", "0x10"), (b"\x01\x00", "0x0100"), - (b"\x00\x0F", "0x000f"), + (b"\x00\x0f", "0x000f"), (b"", "0x"), (0, "0x0"), (1, "0x1"), diff --git a/web3/_utils/abi.py b/web3/_utils/abi.py index df4902635b..9fad0e6b42 100644 --- a/web3/_utils/abi.py +++ b/web3/_utils/abi.py @@ -101,9 +101,7 @@ ) if TYPE_CHECKING: - from web3 import ( # noqa: F401 - AsyncWeb3, - ) + from web3.main import AsyncWeb3 # noqa: F401 def fallback_func_abi_exists(contract_abi: ABI) -> Sequence[ABIFallback]: @@ -852,7 +850,7 @@ def _named_subtree( def recursive_dict_to_namedtuple(data: Dict[str, Any]) -> Tuple[Any, ...]: def _dict_to_namedtuple( - value: Union[Dict[str, Any], List[Any]] + value: Union[Dict[str, Any], List[Any]], ) -> Union[Tuple[Any, ...], List[Any]]: if not isinstance(value, dict): return value @@ -864,7 +862,7 @@ def _dict_to_namedtuple( def abi_decoded_namedtuple_factory( - fields: Tuple[Any, ...] + fields: Tuple[Any, ...], ) -> Callable[..., Tuple[Any, ...]]: class ABIDecodedNamedTuple(namedtuple("ABIDecodedNamedTuple", fields, rename=True)): # type: ignore # noqa: E501 def __new__(self, args: Any) -> "ABIDecodedNamedTuple": @@ -877,9 +875,9 @@ def __new__(self, args: Any) -> "ABIDecodedNamedTuple": async def async_data_tree_map( - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", func: Callable[ - ["AsyncWeb3", TypeStr, Any], Coroutine[Any, Any, Tuple[TypeStr, Any]] + ["AsyncWeb3[Any]", TypeStr, Any], Coroutine[Any, Any, Tuple[TypeStr, Any]] ], data_tree: Any, ) -> "ABITypedData": @@ -902,7 +900,7 @@ async def async_map_to_typed_data(elements: Any) -> "ABITypedData": @reject_recursive_repeats async def async_recursive_map( - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", func: Callable[[Any], Coroutine[Any, Any, TReturn]], data: Any, ) -> TReturn: diff --git a/web3/_utils/async_transactions.py b/web3/_utils/async_transactions.py index 857fc5a52a..b9d2400782 100644 --- a/web3/_utils/async_transactions.py +++ b/web3/_utils/async_transactions.py @@ -1,5 +1,6 @@ from typing import ( TYPE_CHECKING, + Any, Dict, Optional, Union, @@ -46,13 +47,13 @@ # unused vars present in these funcs because they all need to have the same signature async def _estimate_gas( - async_w3: "AsyncWeb3", tx: TxParams, _defaults: Dict[str, Union[bytes, int]] + async_w3: "AsyncWeb3[Any]", tx: TxParams, _defaults: Dict[str, Union[bytes, int]] ) -> int: return await async_w3.eth.estimate_gas(tx) async def _max_fee_per_gas( - async_w3: "AsyncWeb3", tx: TxParams, defaults: Dict[str, Union[bytes, int]] + async_w3: "AsyncWeb3[Any]", tx: TxParams, defaults: Dict[str, Union[bytes, int]] ) -> Wei: block = await async_w3.eth.get_block("latest") max_priority_fee = tx.get( @@ -62,13 +63,13 @@ async def _max_fee_per_gas( async def _max_priority_fee_gas( - async_w3: "AsyncWeb3", _tx: TxParams, _defaults: Dict[str, Union[bytes, int]] + async_w3: "AsyncWeb3[Any]", _tx: TxParams, _defaults: Dict[str, Union[bytes, int]] ) -> Wei: return await async_w3.eth.max_priority_fee async def _chain_id( - async_w3: "AsyncWeb3", _tx: TxParams, _defaults: Dict[str, Union[bytes, int]] + async_w3: "AsyncWeb3[Any]", _tx: TxParams, _defaults: Dict[str, Union[bytes, int]] ) -> int: return await async_w3.eth.chain_id @@ -92,7 +93,7 @@ async def get_block_gas_limit( async def get_buffered_gas_estimate( - async_w3: "AsyncWeb3", transaction: TxParams, gas_buffer: int = 100000 + async_w3: "AsyncWeb3[Any]", transaction: TxParams, gas_buffer: int = 100000 ) -> int: gas_estimate_transaction = cast(TxParams, dict(**transaction)) @@ -110,7 +111,9 @@ async def get_buffered_gas_estimate( return min(gas_limit, gas_estimate + gas_buffer) -async def async_fill_nonce(async_w3: "AsyncWeb3", transaction: TxParams) -> TxParams: +async def async_fill_nonce( + async_w3: "AsyncWeb3[Any]", transaction: TxParams +) -> TxParams: if "from" in transaction and "nonce" not in transaction: tx_count = await async_w3.eth.get_transaction_count( cast(ChecksumAddress, transaction["from"]), @@ -121,7 +124,7 @@ async def async_fill_nonce(async_w3: "AsyncWeb3", transaction: TxParams) -> TxPa async def async_fill_transaction_defaults( - async_w3: "AsyncWeb3", transaction: TxParams + async_w3: "AsyncWeb3[Any]", transaction: TxParams ) -> TxParams: """ If async_w3 is None, fill as much as possible while offline @@ -165,7 +168,7 @@ async def async_fill_transaction_defaults( async def async_get_required_transaction( - async_w3: "AsyncWeb3", transaction_hash: _Hash32 + async_w3: "AsyncWeb3[Any]", transaction_hash: _Hash32 ) -> TxData: current_transaction = await async_w3.eth.get_transaction(transaction_hash) if not current_transaction: @@ -176,7 +179,7 @@ async def async_get_required_transaction( async def async_replace_transaction( - async_w3: "AsyncWeb3", current_transaction: TxData, new_transaction: TxParams + async_w3: "AsyncWeb3[Any]", current_transaction: TxData, new_transaction: TxParams ) -> HexBytes: new_transaction = prepare_replacement_transaction( async_w3, current_transaction, new_transaction diff --git a/web3/_utils/batching.py b/web3/_utils/batching.py index fe16b77f86..462a3eb376 100644 --- a/web3/_utils/batching.py +++ b/web3/_utils/batching.py @@ -71,7 +71,7 @@ class RequestBatcher(Generic[TFunc]): - def __init__(self, web3: Union["AsyncWeb3", "Web3"]) -> None: + def __init__(self, web3: Union["AsyncWeb3[Any]", "Web3"]) -> None: self.web3 = web3 self._requests_info: List[BatchRequestInformation] = [] self._async_requests_info: List[ @@ -167,9 +167,9 @@ def __exit__( async def async_execute(self) -> List["RPCResponse"]: self._validate_is_batching() if self._provider.has_persistent_connection: - responses = await self.web3.manager._async_make_socket_batch_request( - self._async_requests_info - ) + responses = await cast( + "AsyncWeb3[Any]", self.web3 + ).manager._async_make_socket_batch_request(self._async_requests_info) else: responses = await self.web3.manager._async_make_batch_request( self._async_requests_info diff --git a/web3/_utils/caching/caching_utils.py b/web3/_utils/caching/caching_utils.py index 0dd5e85b73..35df8f5485 100644 --- a/web3/_utils/caching/caching_utils.py +++ b/web3/_utils/caching/caching_utils.py @@ -238,7 +238,7 @@ def _should_cache_response( def handle_request_caching( - func: Callable[[SYNC_PROVIDER_TYPE, RPCEndpoint, Any], "RPCResponse"] + func: Callable[[SYNC_PROVIDER_TYPE, RPCEndpoint, Any], "RPCResponse"], ) -> Callable[..., "RPCResponse"]: def wrapper( provider: SYNC_PROVIDER_TYPE, method: RPCEndpoint, params: Any @@ -401,7 +401,7 @@ def async_handle_recv_caching( func: Callable[ ["PersistentConnectionProvider", "RPCRequest"], Coroutine[Any, Any, "RPCResponse"], - ] + ], ) -> Callable[..., Coroutine[Any, Any, "RPCResponse"]]: async def wrapper( provider: "PersistentConnectionProvider", diff --git a/web3/_utils/contracts.py b/web3/_utils/contracts.py index 812729c0f3..c46d59b717 100644 --- a/web3/_utils/contracts.py +++ b/web3/_utils/contracts.py @@ -121,7 +121,7 @@ def find_matching_event_abi( def encode_abi( - w3: Union["AsyncWeb3", "Web3"], + w3: Union["AsyncWeb3[Any]", "Web3"], abi: ABIElement, arguments: Sequence[Any], data: Optional[HexStr] = None, @@ -168,7 +168,7 @@ def encode_abi( def prepare_transaction( address: ChecksumAddress, - w3: Union["AsyncWeb3", "Web3"], + w3: Union["AsyncWeb3[Any]", "Web3"], abi_element_identifier: ABIElementIdentifier, contract_abi: Optional[ABI] = None, abi_callable: Optional[ABICallable] = None, @@ -232,7 +232,7 @@ def prepare_transaction( def encode_transaction_data( - w3: Union["AsyncWeb3", "Web3"], + w3: Union["AsyncWeb3[Any]", "Web3"], abi_element_identifier: ABIElementIdentifier, contract_abi: Optional[ABI] = None, abi_callable: Optional[ABICallable] = None, @@ -363,7 +363,7 @@ def parse_block_identifier_int(w3: "Web3", block_identifier_int: int) -> BlockNu async def async_parse_block_identifier( - async_w3: "AsyncWeb3", block_identifier: BlockIdentifier + async_w3: "AsyncWeb3[Any]", block_identifier: BlockIdentifier ) -> BlockIdentifier: if block_identifier is None: return async_w3.eth.default_block @@ -381,7 +381,7 @@ async def async_parse_block_identifier( async def async_parse_block_identifier_int( - async_w3: "AsyncWeb3", block_identifier_int: int + async_w3: "AsyncWeb3[Any]", block_identifier_int: int ) -> BlockNumber: if block_identifier_int >= 0: block_num = block_identifier_int diff --git a/web3/_utils/ens.py b/web3/_utils/ens.py index 0994838aed..ef29377519 100644 --- a/web3/_utils/ens.py +++ b/web3/_utils/ens.py @@ -75,7 +75,7 @@ async def address(self, name: str) -> ChecksumAddress: @contextmanager def ens_addresses( - w3: Union["Web3", "AsyncWeb3"], name_addr_pairs: Dict[str, ChecksumAddress] + w3: Union["Web3", "AsyncWeb3[Any]"], name_addr_pairs: Dict[str, ChecksumAddress] ) -> Iterator[None]: original_ens = w3.ens if w3.provider.is_async: diff --git a/web3/_utils/events.py b/web3/_utils/events.py index 6658614ad8..6e974722a8 100644 --- a/web3/_utils/events.py +++ b/web3/_utils/events.py @@ -453,7 +453,7 @@ def deploy(self, w3: "Web3") -> "LogFilter": class AsyncEventFilterBuilder(BaseEventFilterBuilder): - async def deploy(self, async_w3: "AsyncWeb3") -> "AsyncLogFilter": + async def deploy(self, async_w3: "AsyncWeb3[Any]") -> "AsyncLogFilter": if not isinstance(async_w3, web3.AsyncWeb3): raise Web3ValueError(f"Invalid web3 argument: got: {async_w3!r}") diff --git a/web3/_utils/module_testing/eth_module.py b/web3/_utils/module_testing/eth_module.py index cff1c51592..67a164a656 100644 --- a/web3/_utils/module_testing/eth_module.py +++ b/web3/_utils/module_testing/eth_module.py @@ -130,7 +130,7 @@ def abi_encoded_offchain_lookup_contract_address( - w3: Union["Web3", "AsyncWeb3"], + w3: Union["Web3", "AsyncWeb3[Any]"], offchain_lookup_contract: Union["Contract", "AsyncContract"], ) -> HexAddress: return HexAddress( @@ -147,20 +147,20 @@ def abi_encoded_offchain_lookup_contract_address( class AsyncEthModuleTest: @pytest.mark.asyncio - async def test_eth_gas_price(self, async_w3: "AsyncWeb3") -> None: + async def test_eth_gas_price(self, async_w3: "AsyncWeb3[Any]") -> None: gas_price = await async_w3.eth.gas_price assert gas_price > 0 @pytest.mark.asyncio - async def test_is_connected(self, async_w3: "AsyncWeb3") -> None: + async def test_is_connected(self, async_w3: "AsyncWeb3[Any]") -> None: is_connected = await async_w3.is_connected() assert is_connected is True @pytest.mark.asyncio async def test_eth_send_transaction_legacy( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -182,7 +182,7 @@ async def test_eth_send_transaction_legacy( @pytest.mark.asyncio async def test_eth_modify_transaction_legacy( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -214,7 +214,7 @@ async def test_eth_modify_transaction_legacy( @pytest.mark.asyncio async def test_eth_modify_transaction( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -252,7 +252,7 @@ async def test_eth_modify_transaction( @pytest.mark.asyncio async def test_async_eth_sign_transaction( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -279,9 +279,9 @@ async def test_async_eth_sign_transaction( @pytest.mark.asyncio async def test_eth_sign_typed_data( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, - async_skip_if_testrpc: Callable[["AsyncWeb3"], None], + async_skip_if_testrpc: Callable[["AsyncWeb3[Any]"], None], ) -> None: validJSONMessage = """ { @@ -333,9 +333,9 @@ async def test_eth_sign_typed_data( @pytest.mark.asyncio async def test_invalid_eth_sign_typed_data( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, - async_skip_if_testrpc: Callable[["AsyncWeb3"], None], + async_skip_if_testrpc: Callable[["AsyncWeb3[Any]"], None], ) -> None: async_skip_if_testrpc(async_w3) invalid_typed_message = """ @@ -388,7 +388,7 @@ async def test_invalid_eth_sign_typed_data( @pytest.mark.asyncio async def test_async_eth_sign_transaction_legacy( - self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress + self, async_w3: "AsyncWeb3[Any]", async_keyfile_account_address: ChecksumAddress ) -> None: txn_params: TxParams = { "from": async_keyfile_account_address, @@ -409,7 +409,7 @@ async def test_async_eth_sign_transaction_legacy( @pytest.mark.asyncio async def test_async_eth_sign_transaction_hex_fees( - self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress + self, async_w3: "AsyncWeb3[Any]", async_keyfile_account_address: ChecksumAddress ) -> None: txn_params: TxParams = { "from": async_keyfile_account_address, @@ -434,7 +434,7 @@ async def test_async_eth_sign_transaction_hex_fees( @pytest.mark.asyncio async def test_async_eth_sign_transaction_ens_names( - self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress + self, async_w3: "AsyncWeb3[Any]", async_keyfile_account_address: ChecksumAddress ) -> None: with ens_addresses( async_w3, {"unlocked-account.eth": async_keyfile_account_address} @@ -464,7 +464,7 @@ async def test_async_eth_sign_transaction_ens_names( @pytest.mark.asyncio async def test_eth_send_transaction( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -490,7 +490,7 @@ async def test_eth_send_transaction( @pytest.mark.asyncio async def test_eth_send_transaction_default_fees( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -514,7 +514,7 @@ async def test_eth_send_transaction_default_fees( @pytest.mark.asyncio async def test_eth_send_transaction_hex_fees( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -538,7 +538,7 @@ async def test_eth_send_transaction_hex_fees( @pytest.mark.asyncio async def test_eth_send_transaction_no_gas( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -559,7 +559,7 @@ async def test_eth_send_transaction_no_gas( @pytest.mark.asyncio async def test_eth_send_transaction_with_gas_price( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -577,7 +577,7 @@ async def test_eth_send_transaction_with_gas_price( @pytest.mark.asyncio async def test_eth_send_transaction_no_priority_fee( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -595,7 +595,7 @@ async def test_eth_send_transaction_no_priority_fee( @pytest.mark.asyncio async def test_eth_send_transaction_no_max_fee( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: maxPriorityFeePerGas = async_w3.to_wei(2, "gwei") @@ -617,7 +617,7 @@ async def test_eth_send_transaction_no_max_fee( @pytest.mark.asyncio async def test_eth_send_transaction_max_fee_less_than_tip( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -636,7 +636,7 @@ async def test_eth_send_transaction_max_fee_less_than_tip( @pytest.mark.asyncio async def test_validation_middleware_chain_id_mismatch( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: wrong_chain_id = 1234567890 @@ -660,7 +660,7 @@ async def test_validation_middleware_chain_id_mismatch( @pytest.mark.asyncio async def test_ExtraDataToPOAMiddleware( - self, async_w3: "AsyncWeb3", request_mocker: Type[RequestMocker] + self, async_w3: "AsyncWeb3[Any]", request_mocker: Type[RequestMocker] ) -> None: async_w3.middleware_onion.inject(ExtraDataToPOAMiddleware, "poa", layer=0) extra_data = f"0x{'ff' * 33}" @@ -679,7 +679,7 @@ async def test_ExtraDataToPOAMiddleware( @pytest.mark.asyncio async def test_async_eth_send_raw_transaction( - self, async_w3: "AsyncWeb3", keyfile_account_pkey: HexStr + self, async_w3: "AsyncWeb3[Any]", keyfile_account_pkey: HexStr ) -> None: keyfile_account = async_w3.eth.account.from_key(keyfile_account_pkey) txn = { @@ -699,7 +699,7 @@ async def test_async_eth_send_raw_transaction( @pytest.mark.asyncio async def test_async_sign_and_send_raw_middleware( - self, async_w3: "AsyncWeb3", keyfile_account_pkey: HexStr + self, async_w3: "AsyncWeb3[Any]", keyfile_account_pkey: HexStr ) -> None: keyfile_account = async_w3.eth.account.from_key(keyfile_account_pkey) txn: TxParams = { @@ -720,7 +720,7 @@ async def test_async_sign_and_send_raw_middleware( @pytest.mark.asyncio async def test_async_sign_authorization_send_raw_and_send_set_code_transactions( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", keyfile_account_pkey: HexStr, async_math_contract: "AsyncContract", ) -> None: @@ -805,7 +805,7 @@ async def test_async_sign_authorization_send_raw_and_send_set_code_transactions( @pytest.mark.asyncio async def test_GasPriceStrategyMiddleware( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -830,7 +830,7 @@ def gas_price_strategy(w3: "Web3", txn: TxParams) -> Wei: @pytest.mark.asyncio async def test_gas_price_strategy_middleware_hex_value( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -858,7 +858,7 @@ def gas_price_strategy(_w3: "Web3", _txn: TxParams) -> str: ) async def test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, max_fee: Wei, ) -> None: @@ -895,7 +895,7 @@ def gas_price_strategy(w3: "Web3", txn: TxParams) -> Wei: @pytest.mark.asyncio async def test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn_no_tip( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -921,7 +921,7 @@ def gas_price_strategy(_w3: "Web3", _txn: TxParams) -> Wei: @pytest.mark.asyncio async def test_eth_estimate_gas( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: gas_estimate = await async_w3.eth.estimate_gas( @@ -956,7 +956,7 @@ async def test_eth_estimate_gas( ) async def test_eth_estimate_gas_with_override_param_type_check( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_math_contract: "AsyncContract", params: StateOverrideParams, ) -> None: @@ -969,7 +969,7 @@ async def test_eth_estimate_gas_with_override_param_type_check( ) @pytest.mark.asyncio - async def test_eth_fee_history(self, async_w3: "AsyncWeb3") -> None: + async def test_eth_fee_history(self, async_w3: "AsyncWeb3[Any]") -> None: fee_history = await async_w3.eth.fee_history(1, "latest", [50]) assert is_list_like(fee_history["baseFeePerGas"]) assert is_list_like(fee_history["gasUsedRatio"]) @@ -981,7 +981,7 @@ async def test_eth_fee_history(self, async_w3: "AsyncWeb3") -> None: @pytest.mark.asyncio async def test_eth_fee_history_with_integer( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: fee_history = await async_w3.eth.fee_history( 1, async_empty_block["number"], [50] @@ -996,7 +996,7 @@ async def test_eth_fee_history_with_integer( @pytest.mark.asyncio async def test_eth_fee_history_no_reward_percentiles( - self, async_w3: "AsyncWeb3" + self, async_w3: "AsyncWeb3[Any]" ) -> None: fee_history = await async_w3.eth.fee_history(1, "latest") assert is_list_like(fee_history["baseFeePerGas"]) @@ -1005,13 +1005,13 @@ async def test_eth_fee_history_no_reward_percentiles( assert fee_history["oldestBlock"] >= 0 @pytest.mark.asyncio - async def test_eth_max_priority_fee(self, async_w3: "AsyncWeb3") -> None: + async def test_eth_max_priority_fee(self, async_w3: "AsyncWeb3[Any]") -> None: max_priority_fee = await async_w3.eth.max_priority_fee assert is_integer(max_priority_fee) @pytest.mark.asyncio async def test_eth_max_priority_fee_with_fee_history_calculation( - self, async_w3: "AsyncWeb3", request_mocker: Type[RequestMocker] + self, async_w3: "AsyncWeb3[Any]", request_mocker: Type[RequestMocker] ) -> None: async with request_mocker( async_w3, @@ -1031,52 +1031,54 @@ async def test_eth_max_priority_fee_with_fee_history_calculation( @pytest.mark.asyncio async def test_eth_getBlockByHash( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: block = await async_w3.eth.get_block(async_empty_block["hash"]) assert block["hash"] == async_empty_block["hash"] @pytest.mark.asyncio - async def test_eth_getBlockByHash_not_found(self, async_w3: "AsyncWeb3") -> None: + async def test_eth_getBlockByHash_not_found( + self, async_w3: "AsyncWeb3[Any]" + ) -> None: with pytest.raises(BlockNotFound): await async_w3.eth.get_block(UNKNOWN_HASH) @pytest.mark.asyncio - async def test_eth_getBlockByHash_pending(self, async_w3: "AsyncWeb3") -> None: + async def test_eth_getBlockByHash_pending(self, async_w3: "AsyncWeb3[Any]") -> None: block = await async_w3.eth.get_block("pending") assert block["hash"] is None @pytest.mark.asyncio async def test_eth_getBlockByNumber_with_integer( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: block = await async_w3.eth.get_block(async_empty_block["number"]) assert block["number"] == async_empty_block["number"] @pytest.mark.asyncio async def test_eth_getBlockByNumber_latest( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: block = await async_w3.eth.get_block("latest") assert block["hash"] is not None @pytest.mark.asyncio async def test_eth_getBlockByNumber_not_found( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: with pytest.raises(BlockNotFound): await async_w3.eth.get_block(BlockNumber(12345)) @pytest.mark.asyncio async def test_eth_getBlockByNumber_pending( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: block = await async_w3.eth.get_block("pending") assert block["hash"] is None @pytest.mark.asyncio async def test_eth_getBlockByNumber_earliest( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: genesis_block = await async_w3.eth.get_block(BlockNumber(0)) block = await async_w3.eth.get_block("earliest") @@ -1085,7 +1087,7 @@ async def test_eth_getBlockByNumber_earliest( @pytest.mark.asyncio async def test_eth_getBlockByNumber_safe( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: block = await async_w3.eth.get_block("safe") assert block is not None @@ -1093,7 +1095,7 @@ async def test_eth_getBlockByNumber_safe( @pytest.mark.asyncio async def test_eth_getBlockByNumber_finalized( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: block = await async_w3.eth.get_block("finalized") assert block is not None @@ -1101,40 +1103,42 @@ async def test_eth_getBlockByNumber_finalized( @pytest.mark.asyncio async def test_eth_getBlockReceipts_hash( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: receipts = await async_w3.eth.get_block_receipts(async_empty_block["hash"]) assert isinstance(receipts, list) @pytest.mark.asyncio - async def test_eth_getBlockReceipts_not_found(self, async_w3: "AsyncWeb3") -> None: + async def test_eth_getBlockReceipts_not_found( + self, async_w3: "AsyncWeb3[Any]" + ) -> None: with pytest.raises(BlockNotFound): await async_w3.eth.get_block_receipts(UNKNOWN_HASH) @pytest.mark.asyncio async def test_eth_getBlockReceipts_with_integer( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: receipts = await async_w3.eth.get_block_receipts(async_empty_block["number"]) assert isinstance(receipts, list) @pytest.mark.asyncio async def test_eth_getBlockReceipts_safe( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: receipts = await async_w3.eth.get_block_receipts("safe") assert isinstance(receipts, list) @pytest.mark.asyncio async def test_eth_getBlockReceipts_finalized( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: receipts = await async_w3.eth.get_block_receipts("finalized") assert isinstance(receipts, list) @pytest.mark.asyncio async def test_eth_get_block_by_number_full_transactions( - self, async_w3: "AsyncWeb3", async_block_with_txn: BlockData + self, async_w3: "AsyncWeb3[Any]", async_block_with_txn: BlockData ) -> None: block = await async_w3.eth.get_block(async_block_with_txn["number"], True) transaction = cast(TxData, block["transactions"][0]) @@ -1142,14 +1146,14 @@ async def test_eth_get_block_by_number_full_transactions( @pytest.mark.asyncio async def test_eth_get_raw_transaction( - self, async_w3: "AsyncWeb3", mined_txn_hash: HexStr + self, async_w3: "AsyncWeb3[Any]", mined_txn_hash: HexStr ) -> None: raw_transaction = await async_w3.eth.get_raw_transaction(mined_txn_hash) assert is_bytes(raw_transaction) @pytest.mark.asyncio async def test_eth_get_raw_transaction_raises_error( - self, async_w3: "AsyncWeb3" + self, async_w3: "AsyncWeb3[Any]" ) -> None: with pytest.raises( TransactionNotFound, match=f"Transaction with hash: '{UNKNOWN_HASH}'" @@ -1159,7 +1163,7 @@ async def test_eth_get_raw_transaction_raises_error( @pytest.mark.asyncio async def test_eth_get_raw_transaction_by_block( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_block_with_txn: BlockData, async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: @@ -1200,7 +1204,9 @@ async def wait_for_block_with_txn() -> HexBytes: @pytest.mark.asyncio @pytest.mark.parametrize("unknown_block_num_or_hash", (1234567899999, UNKNOWN_HASH)) async def test_eth_get_raw_transaction_by_block_raises_error( - self, async_w3: "AsyncWeb3", unknown_block_num_or_hash: Union[int, HexBytes] + self, + async_w3: "AsyncWeb3[Any]", + unknown_block_num_or_hash: Union[int, HexBytes], ) -> None: with pytest.raises( TransactionNotFound, @@ -1216,7 +1222,7 @@ async def test_eth_get_raw_transaction_by_block_raises_error( @pytest.mark.asyncio async def test_eth_get_raw_transaction_by_block_raises_error_block_identifier( - self, async_w3: "AsyncWeb3" + self, async_w3: "AsyncWeb3[Any]" ) -> None: unknown_identifier = "unknown" with pytest.raises( @@ -1230,7 +1236,7 @@ async def test_eth_get_raw_transaction_by_block_raises_error_block_identifier( await async_w3.eth.get_raw_transaction_by_block(unknown_identifier, 0) # type: ignore # noqa: E501 @pytest.mark.asyncio - async def test_eth_get_balance(self, async_w3: "AsyncWeb3") -> None: + async def test_eth_get_balance(self, async_w3: "AsyncWeb3[Any]") -> None: accounts = await async_w3.eth.accounts account = accounts[0] @@ -1246,7 +1252,7 @@ async def test_eth_get_balance(self, async_w3: "AsyncWeb3") -> None: @pytest.mark.asyncio async def test_eth_get_code( - self, async_w3: "AsyncWeb3", async_math_contract_address: ChecksumAddress + self, async_w3: "AsyncWeb3[Any]", async_math_contract_address: ChecksumAddress ) -> None: code = await async_w3.eth.get_code(async_math_contract_address) assert isinstance(code, HexBytes) @@ -1255,7 +1261,7 @@ async def test_eth_get_code( @pytest.mark.asyncio async def test_eth_get_code_invalid_address( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_math_contract: "AsyncContract", ) -> None: with pytest.raises(InvalidAddress): @@ -1265,7 +1271,7 @@ async def test_eth_get_code_invalid_address( @pytest.mark.asyncio async def test_eth_get_code_with_block_identifier( - self, async_w3: "AsyncWeb3", async_emitter_contract: "AsyncContract" + self, async_w3: "AsyncWeb3[Any]", async_emitter_contract: "AsyncContract" ) -> None: block_id = await async_w3.eth.block_number code = await async_w3.eth.get_code(async_emitter_contract.address, block_id) @@ -1275,7 +1281,7 @@ async def test_eth_get_code_with_block_identifier( @pytest.mark.asyncio async def test_eth_create_access_list( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, async_math_contract: "AsyncContract", ) -> None: @@ -1305,7 +1311,7 @@ async def test_eth_create_access_list( @pytest.mark.asyncio async def test_eth_get_transaction_count( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: transaction_count = await async_w3.eth.get_transaction_count( @@ -1316,7 +1322,7 @@ async def test_eth_get_transaction_count( @pytest.mark.asyncio async def test_eth_call( - self, async_w3: "AsyncWeb3", async_math_contract: "AsyncContract" + self, async_w3: "AsyncWeb3[Any]", async_math_contract: "AsyncContract" ) -> None: accounts = await async_w3.eth.accounts account = accounts[0] @@ -1334,7 +1340,7 @@ async def test_eth_call( @pytest.mark.asyncio async def test_eth_call_with_override_code( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_revert_contract: "AsyncContract", ) -> None: accounts = await async_w3.eth.accounts @@ -1391,7 +1397,7 @@ async def test_eth_call_with_override_code( ) async def test_eth_call_with_override_param_type_check( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_math_contract: "AsyncContract", params: StateOverrideParams, ) -> None: @@ -1405,7 +1411,7 @@ async def test_eth_call_with_override_param_type_check( @pytest.mark.asyncio async def test_eth_call_with_0_result( - self, async_w3: "AsyncWeb3", async_math_contract: "AsyncContract" + self, async_w3: "AsyncWeb3[Any]", async_math_contract: "AsyncContract" ) -> None: accounts = await async_w3.eth.accounts txn_params = async_math_contract._prepare_transaction( @@ -1421,7 +1427,7 @@ async def test_eth_call_with_0_result( @pytest.mark.asyncio async def test_eth_call_revert_with_msg( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_revert_contract: "AsyncContract", async_keyfile_account_address: ChecksumAddress, ) -> None: @@ -1440,7 +1446,7 @@ async def test_eth_call_revert_with_msg( @pytest.mark.asyncio async def test_eth_call_revert_without_msg( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_revert_contract: "AsyncContract", async_keyfile_account_address: ChecksumAddress, ) -> None: @@ -1457,7 +1463,7 @@ async def test_eth_call_revert_without_msg( @pytest.mark.asyncio async def test_eth_call_revert_custom_error_with_msg( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_revert_contract: "AsyncContract", async_keyfile_account_address: ChecksumAddress, ) -> None: @@ -1478,7 +1484,7 @@ async def test_eth_call_revert_custom_error_with_msg( @pytest.mark.asyncio async def test_eth_call_revert_custom_error_without_msg( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_revert_contract: "AsyncContract", async_keyfile_account_address: ChecksumAddress, ) -> None: @@ -1510,7 +1516,7 @@ async def test_eth_call_revert_custom_error_without_msg( @pytest.mark.asyncio async def test_contract_panic_errors( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_panic_errors_contract: "AsyncContract", panic_error: str, params: List[Any], @@ -1527,7 +1533,7 @@ async def test_contract_panic_errors( @pytest.mark.asyncio async def test_eth_call_offchain_lookup( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_offchain_lookup_contract: "AsyncContract", async_keyfile_account_address: ChecksumAddress, monkeypatch: "MonkeyPatch", @@ -1553,7 +1559,7 @@ async def test_eth_call_offchain_lookup( @pytest.mark.asyncio async def test_eth_call_offchain_lookup_raises_when_ccip_read_is_disabled( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_offchain_lookup_contract: "AsyncContract", ) -> None: return_data = ( @@ -1591,7 +1597,7 @@ async def test_eth_call_offchain_lookup_raises_when_ccip_read_is_disabled( @pytest.mark.asyncio async def test_eth_call_offchain_lookup_call_flag_overrides_provider_flag( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_offchain_lookup_contract: "AsyncContract", async_keyfile_account_address: ChecksumAddress, monkeypatch: "MonkeyPatch", @@ -1619,7 +1625,7 @@ async def test_eth_call_offchain_lookup_call_flag_overrides_provider_flag( @pytest.mark.parametrize("max_redirects", range(-1, 4)) async def test_eth_call_offchain_lookup_raises_if_max_redirects_is_less_than_4( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_offchain_lookup_contract: "AsyncContract", max_redirects: int, ) -> None: @@ -1636,7 +1642,7 @@ async def test_eth_call_offchain_lookup_raises_if_max_redirects_is_less_than_4( @pytest.mark.asyncio async def test_eth_call_offchain_lookup_raises_for_improperly_formatted_rest_request_response( # noqa: E501 self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_offchain_lookup_contract: "AsyncContract", async_keyfile_account_address: ChecksumAddress, monkeypatch: "MonkeyPatch", @@ -1660,7 +1666,7 @@ async def test_eth_call_offchain_lookup_raises_for_improperly_formatted_rest_req @pytest.mark.parametrize("status_code_non_4xx_error", [100, 300, 500, 600]) async def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_and_tests_POST( # noqa: E501 self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_offchain_lookup_contract: "AsyncContract", async_keyfile_account_address: ChecksumAddress, monkeypatch: "MonkeyPatch", @@ -1698,7 +1704,7 @@ async def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_ @pytest.mark.asyncio async def test_eth_call_offchain_lookup_calls_raise_for_status_for_4xx_status_code( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_offchain_lookup_contract: "AsyncContract", async_keyfile_account_address: ChecksumAddress, monkeypatch: "MonkeyPatch", @@ -1749,7 +1755,7 @@ async def test_eth_call_continuous_offchain_lookup_raises_with_too_many_requests await async_offchain_lookup_contract.caller().continuousOffchainLookup() # noqa: E501 type: ignore @pytest.mark.asyncio - async def test_eth_simulate_v1(self, async_w3: "AsyncWeb3") -> None: + async def test_eth_simulate_v1(self, async_w3: "AsyncWeb3[Any]") -> None: simulate_result = await async_w3.eth.simulate_v1( { "blockStateCalls": [ @@ -1795,7 +1801,7 @@ async def test_eth_simulate_v1(self, async_w3: "AsyncWeb3") -> None: assert call_entry["gasUsed"] == int("0x5208", 16) @pytest.mark.asyncio - async def test_async_eth_chain_id(self, async_w3: "AsyncWeb3") -> None: + async def test_async_eth_chain_id(self, async_w3: "AsyncWeb3[Any]") -> None: chain_id = await async_w3.eth.chain_id # chain id value from geth fixture genesis file assert chain_id == 131277322940537 @@ -1803,7 +1809,7 @@ async def test_async_eth_chain_id(self, async_w3: "AsyncWeb3") -> None: @pytest.mark.asyncio async def test_async_eth_get_transaction_receipt_mined( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_block_with_txn: BlockData, mined_txn_hash: HexStr, ) -> None: @@ -1824,7 +1830,7 @@ async def test_async_eth_get_transaction_receipt_mined( @pytest.mark.asyncio async def test_async_eth_get_transaction_receipt_unmined( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_hash = await async_w3.eth.send_transaction( @@ -1843,7 +1849,7 @@ async def test_async_eth_get_transaction_receipt_unmined( @pytest.mark.asyncio async def test_async_eth_get_transaction_receipt_with_log_entry( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_block_with_txn_with_log: BlockData, async_emitter_contract: "AsyncContract", txn_hash_with_log: HexStr, @@ -1868,7 +1874,7 @@ async def test_async_eth_get_transaction_receipt_with_log_entry( @pytest.mark.asyncio async def test_async_eth_wait_for_transaction_receipt_mined( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_block_with_txn: BlockData, mined_txn_hash: HexStr, ) -> None: @@ -1893,7 +1899,7 @@ async def test_async_eth_wait_for_transaction_receipt_mined( ) async def test_async_eth_wait_for_transaction_receipt_unmined( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_hash = await async_w3.eth.send_transaction( @@ -1916,7 +1922,7 @@ async def test_async_eth_wait_for_transaction_receipt_unmined( @pytest.mark.asyncio async def test_async_eth_wait_for_transaction_receipt_with_log_entry( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_block_with_txn_with_log: BlockData, async_emitter_contract: "AsyncContract", txn_hash_with_log: HexStr, @@ -1939,21 +1945,21 @@ async def test_async_eth_wait_for_transaction_receipt_with_log_entry( assert log_entry["transactionHash"] == HexBytes(txn_hash_with_log) @pytest.mark.asyncio - async def test_async_eth_accounts(self, async_w3: "AsyncWeb3") -> None: + async def test_async_eth_accounts(self, async_w3: "AsyncWeb3[Any]") -> None: accounts = await async_w3.eth.accounts assert is_list_like(accounts) assert len(accounts) != 0 assert all(is_checksum_address(account) for account in accounts) @pytest.mark.asyncio - async def test_async_eth_blob_base_fee(self, async_w3: "AsyncWeb3") -> None: + async def test_async_eth_blob_base_fee(self, async_w3: "AsyncWeb3[Any]") -> None: blob_base_fee = await async_w3.eth.blob_base_fee assert is_integer(blob_base_fee) assert blob_base_fee >= 0 @pytest.mark.asyncio async def test_async_eth_get_logs_without_logs( - self, async_w3: "AsyncWeb3", async_block_with_txn_with_log: BlockData + self, async_w3: "AsyncWeb3[Any]", async_block_with_txn_with_log: BlockData ) -> None: # Test with block range @@ -1995,7 +2001,7 @@ async def test_async_eth_get_logs_without_logs( @pytest.mark.asyncio async def test_async_eth_get_logs_with_logs( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_block_with_txn_with_log: BlockData, async_emitter_contract_address: ChecksumAddress, txn_hash_with_log: HexStr, @@ -2045,7 +2051,7 @@ async def test_async_eth_get_logs_with_logs( @pytest.mark.asyncio async def test_async_eth_get_logs_with_logs_topic_args( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_block_with_txn_with_log: BlockData, async_emitter_contract_address: ChecksumAddress, txn_hash_with_log: HexStr, @@ -2090,7 +2096,7 @@ async def test_async_eth_get_logs_with_logs_topic_args( @pytest.mark.asyncio async def test_async_eth_get_logs_with_logs_none_topic_args( - self, async_w3: "AsyncWeb3" + self, async_w3: "AsyncWeb3[Any]" ) -> None: # Test with None overflowing filter_params: FilterParams = { @@ -2101,7 +2107,7 @@ async def test_async_eth_get_logs_with_logs_none_topic_args( assert len(result) == 0 @pytest.mark.asyncio - async def test_async_eth_syncing(self, async_w3: "AsyncWeb3") -> None: + async def test_async_eth_syncing(self, async_w3: "AsyncWeb3[Any]") -> None: syncing = await async_w3.eth.syncing assert is_boolean(syncing) or is_dict(syncing) @@ -2120,7 +2126,7 @@ async def test_async_eth_syncing(self, async_w3: "AsyncWeb3") -> None: @pytest.mark.asyncio async def test_async_eth_get_storage_at( - self, async_w3: "AsyncWeb3", async_storage_contract: "AsyncContract" + self, async_w3: "AsyncWeb3[Any]", async_storage_contract: "AsyncContract" ) -> None: async_storage_contract_address = async_storage_contract.address @@ -2147,7 +2153,7 @@ async def test_async_eth_get_storage_at( @pytest.mark.asyncio async def test_async_eth_get_storage_at_ens_name( - self, async_w3: "AsyncWeb3", async_storage_contract: "AsyncContract" + self, async_w3: "AsyncWeb3[Any]", async_storage_contract: "AsyncContract" ) -> None: with ens_addresses(async_w3, {"storage.eth": async_storage_contract.address}): storage = await async_w3.eth.get_storage_at(ENS("storage.eth"), 1) @@ -2155,7 +2161,7 @@ async def test_async_eth_get_storage_at_ens_name( @pytest.mark.asyncio async def test_async_eth_get_storage_at_invalid_address( - self, async_w3: "AsyncWeb3" + self, async_w3: "AsyncWeb3[Any]" ) -> None: accounts = await async_w3.eth.accounts with pytest.raises(InvalidAddress): @@ -2165,7 +2171,7 @@ async def test_async_eth_get_storage_at_invalid_address( def test_async_provider_default_account( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: current_default_account = async_w3.eth.default_account @@ -2180,7 +2186,7 @@ def test_async_provider_default_account( def test_async_provider_default_block( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", ) -> None: # check defaults to 'latest' default_block = async_w3.eth.default_block @@ -2196,7 +2202,7 @@ def test_async_provider_default_block( @pytest.mark.asyncio async def test_eth_getBlockTransactionCountByHash_async_empty_block( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: transaction_count = await async_w3.eth.get_block_transaction_count( async_empty_block["hash"] @@ -2207,7 +2213,7 @@ async def test_eth_getBlockTransactionCountByHash_async_empty_block( @pytest.mark.asyncio async def test_eth_getBlockTransactionCountByNumber_async_empty_block( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: transaction_count = await async_w3.eth.get_block_transaction_count( async_empty_block["number"] @@ -2218,7 +2224,7 @@ async def test_eth_getBlockTransactionCountByNumber_async_empty_block( @pytest.mark.asyncio async def test_eth_getBlockTransactionCountByHash_block_with_txn( - self, async_w3: "AsyncWeb3", async_block_with_txn: BlockData + self, async_w3: "AsyncWeb3[Any]", async_block_with_txn: BlockData ) -> None: transaction_count = await async_w3.eth.get_block_transaction_count( async_block_with_txn["hash"] @@ -2229,7 +2235,7 @@ async def test_eth_getBlockTransactionCountByHash_block_with_txn( @pytest.mark.asyncio async def test_eth_getUncleCountByBlockHash( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: with pytest.warns( DeprecationWarning, @@ -2243,7 +2249,7 @@ async def test_eth_getUncleCountByBlockHash( @pytest.mark.asyncio async def test_eth_getUncleCountByBlockNumber( - self, async_w3: "AsyncWeb3", async_empty_block: BlockData + self, async_w3: "AsyncWeb3[Any]", async_empty_block: BlockData ) -> None: with pytest.warns( DeprecationWarning, @@ -2259,7 +2265,7 @@ async def test_eth_getUncleCountByBlockNumber( @pytest.mark.asyncio async def test_eth_getBlockTransactionCountByNumber_block_with_txn( - self, async_w3: "AsyncWeb3", async_block_with_txn: BlockData + self, async_w3: "AsyncWeb3[Any]", async_block_with_txn: BlockData ) -> None: transaction_count = await async_w3.eth.get_block_transaction_count( async_block_with_txn["number"] @@ -2271,7 +2277,7 @@ async def test_eth_getBlockTransactionCountByNumber_block_with_txn( @pytest.mark.asyncio async def test_async_eth_sign( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: signature = await async_w3.eth.sign( @@ -2311,7 +2317,7 @@ async def test_async_eth_sign( @pytest.mark.asyncio async def test_async_eth_sign_ens_names( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: with ens_addresses( @@ -2326,7 +2332,7 @@ async def test_async_eth_sign_ens_names( @pytest.mark.asyncio async def test_async_eth_replace_transaction_legacy( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -2355,7 +2361,7 @@ async def test_async_eth_replace_transaction_legacy( @pytest.mark.asyncio async def test_async_eth_replace_transaction( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: two_gwei_in_wei = async_w3.to_wei(2, "gwei") @@ -2391,7 +2397,7 @@ async def test_async_eth_replace_transaction( @pytest.mark.asyncio async def test_async_eth_replace_transaction_underpriced( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: # Note: `underpriced transaction` error is only consistent with @@ -2417,7 +2423,7 @@ async def test_async_eth_replace_transaction_underpriced( @pytest.mark.asyncio async def test_async_eth_replace_transaction_non_existing_transaction( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -2439,7 +2445,7 @@ async def test_async_eth_replace_transaction_non_existing_transaction( @pytest.mark.asyncio async def test_async_eth_replace_transaction_already_mined( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -2460,7 +2466,7 @@ async def test_async_eth_replace_transaction_already_mined( @pytest.mark.asyncio async def test_async_eth_replace_transaction_incorrect_nonce( - self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress + self, async_w3: "AsyncWeb3[Any]", async_keyfile_account_address: ChecksumAddress ) -> None: txn_params: TxParams = { "from": async_keyfile_account_address, @@ -2482,7 +2488,7 @@ async def test_async_eth_replace_transaction_incorrect_nonce( @pytest.mark.asyncio async def test_async_eth_replace_transaction_gas_price_too_low( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", async_keyfile_account_address_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { @@ -2500,7 +2506,7 @@ async def test_async_eth_replace_transaction_gas_price_too_low( @pytest.mark.asyncio async def test_async_eth_replace_transaction_gas_price_defaulting_minimum( - self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress + self, async_w3: "AsyncWeb3[Any]", async_keyfile_account_address: ChecksumAddress ) -> None: gas_price = async_w3.to_wei(1, "gwei") @@ -2523,7 +2529,7 @@ async def test_async_eth_replace_transaction_gas_price_defaulting_minimum( @pytest.mark.asyncio async def test_async_eth_replace_transaction_gas_price_defaulting_strategy_higher( - self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress + self, async_w3: "AsyncWeb3[Any]", async_keyfile_account_address: ChecksumAddress ) -> None: txn_params: TxParams = { "from": async_keyfile_account_address, @@ -2536,7 +2542,9 @@ async def test_async_eth_replace_transaction_gas_price_defaulting_strategy_highe two_gwei_in_wei = async_w3.to_wei(2, "gwei") - def higher_gas_price_strategy(_async_w3: "AsyncWeb3", _txn: TxParams) -> Wei: + def higher_gas_price_strategy( + _async_w3: "AsyncWeb3[Any]", _txn: TxParams + ) -> Wei: return two_gwei_in_wei async_w3.eth.set_gas_price_strategy(higher_gas_price_strategy) @@ -2551,7 +2559,7 @@ def higher_gas_price_strategy(_async_w3: "AsyncWeb3", _txn: TxParams) -> Wei: @pytest.mark.asyncio async def test_async_eth_replace_transaction_gas_price_defaulting_strategy_lower( - self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress + self, async_w3: "AsyncWeb3[Any]", async_keyfile_account_address: ChecksumAddress ) -> None: gas_price = async_w3.to_wei(2, "gwei") txn_params: TxParams = { @@ -2563,7 +2571,7 @@ async def test_async_eth_replace_transaction_gas_price_defaulting_strategy_lower } txn_hash = await async_w3.eth.send_transaction(txn_params) - def lower_gas_price_strategy(async_w3: "AsyncWeb3", txn: TxParams) -> Wei: + def lower_gas_price_strategy(async_w3: "AsyncWeb3[Any]", txn: TxParams) -> Wei: return async_w3.to_wei(1, "gwei") async_w3.eth.set_gas_price_strategy(lower_gas_price_strategy) @@ -2576,7 +2584,7 @@ def lower_gas_price_strategy(async_w3: "AsyncWeb3", txn: TxParams) -> Wei: async_w3.eth.set_gas_price_strategy(None) # reset strategy @pytest.mark.asyncio - async def test_async_eth_new_filter(self, async_w3: "AsyncWeb3") -> None: + async def test_async_eth_new_filter(self, async_w3: "AsyncWeb3[Any]") -> None: filter = await async_w3.eth.filter({}) changes = await async_w3.eth.get_filter_changes(filter.filter_id) @@ -2591,7 +2599,7 @@ async def test_async_eth_new_filter(self, async_w3: "AsyncWeb3") -> None: assert result is True @pytest.mark.asyncio - async def test_async_eth_new_block_filter(self, async_w3: "AsyncWeb3") -> None: + async def test_async_eth_new_block_filter(self, async_w3: "AsyncWeb3[Any]") -> None: filter = await async_w3.eth.filter("latest") assert is_string(filter.filter_id) @@ -2603,7 +2611,7 @@ async def test_async_eth_new_block_filter(self, async_w3: "AsyncWeb3") -> None: @pytest.mark.asyncio async def test_async_eth_new_pending_transaction_filter( - self, async_w3: "AsyncWeb3" + self, async_w3: "AsyncWeb3[Any]" ) -> None: filter = await async_w3.eth.filter("pending") assert is_string(filter.filter_id) @@ -2616,7 +2624,7 @@ async def test_async_eth_new_pending_transaction_filter( assert result is True @pytest.mark.asyncio - async def test_async_eth_uninstall_filter(self, async_w3: "AsyncWeb3") -> None: + async def test_async_eth_uninstall_filter(self, async_w3: "AsyncWeb3[Any]") -> None: filter = await async_w3.eth.filter({}) assert is_string(filter.filter_id) diff --git a/web3/_utils/module_testing/go_ethereum_admin_module.py b/web3/_utils/module_testing/go_ethereum_admin_module.py index 37db5a48e5..952147bc9c 100644 --- a/web3/_utils/module_testing/go_ethereum_admin_module.py +++ b/web3/_utils/module_testing/go_ethereum_admin_module.py @@ -1,6 +1,7 @@ import pytest from typing import ( TYPE_CHECKING, + Any, List, ) @@ -70,29 +71,29 @@ def test_admin_start_stop_ws(self, w3: "Web3") -> None: class GoEthereumAsyncAdminModuleTest: @pytest.mark.asyncio - async def test_async_datadir(self, async_w3: "AsyncWeb3") -> None: + async def test_async_datadir(self, async_w3: "AsyncWeb3[Any]") -> None: datadir = await async_w3.geth.admin.datadir() assert isinstance(datadir, str) @pytest.mark.asyncio - async def test_async_node_info(self, async_w3: "AsyncWeb3") -> None: + async def test_async_node_info(self, async_w3: "AsyncWeb3[Any]") -> None: node_info = await async_w3.geth.admin.node_info() assert "Geth" in node_info["name"] @pytest.mark.asyncio - async def test_async_nodes(self, async_w3: "AsyncWeb3") -> None: + async def test_async_nodes(self, async_w3: "AsyncWeb3[Any]") -> None: nodes = await async_w3.geth.admin.peers() assert isinstance(nodes, List) @pytest.mark.asyncio - async def test_admin_peers(self, async_w3: "AsyncWeb3") -> None: + async def test_admin_peers(self, async_w3: "AsyncWeb3[Any]") -> None: node_info = await async_w3.geth.admin.node_info() await async_w3.geth.admin.add_peer(node_info["enode"]) result = await async_w3.geth.admin.peers() assert len(result) == 1 @pytest.mark.asyncio - async def test_admin_start_stop_http(self, async_w3: "AsyncWeb3") -> None: + async def test_admin_start_stop_http(self, async_w3: "AsyncWeb3[Any]") -> None: stop = await async_w3.geth.admin.stop_http() assert stop is True @@ -100,7 +101,7 @@ async def test_admin_start_stop_http(self, async_w3: "AsyncWeb3") -> None: assert start is True @pytest.mark.asyncio - async def test_admin_start_stop_ws(self, async_w3: "AsyncWeb3") -> None: + async def test_admin_start_stop_ws(self, async_w3: "AsyncWeb3[Any]") -> None: stop = await async_w3.geth.admin.stop_ws() assert stop is True diff --git a/web3/_utils/module_testing/go_ethereum_debug_module.py b/web3/_utils/module_testing/go_ethereum_debug_module.py index eecc352f9d..c5fc362624 100644 --- a/web3/_utils/module_testing/go_ethereum_debug_module.py +++ b/web3/_utils/module_testing/go_ethereum_debug_module.py @@ -1,5 +1,6 @@ import pytest from typing import ( + Any, cast, ) @@ -24,7 +25,7 @@ class GoEthereumAsyncDebugModuleTest: @pytest.mark.asyncio async def test_async_geth_debug_trace_transaction_opcode_logger( - self, async_w3: "AsyncWeb3", txn_hash_with_log: HexStr + self, async_w3: "AsyncWeb3[Any]", txn_hash_with_log: HexStr ) -> None: result = await async_w3.geth.debug.trace_transaction(txn_hash_with_log) assert "structLogs" in dict(result).keys() @@ -33,7 +34,7 @@ async def test_async_geth_debug_trace_transaction_opcode_logger( @pytest.mark.asyncio async def test_async_geth_debug_trace_transaction_call_tracer( - self, async_w3: "AsyncWeb3", txn_hash_with_log: HexStr + self, async_w3: "AsyncWeb3[Any]", txn_hash_with_log: HexStr ) -> None: result = cast( CallTrace, @@ -45,7 +46,7 @@ async def test_async_geth_debug_trace_transaction_call_tracer( @pytest.mark.asyncio async def test_async_geth_debug_trace_transaction_prestate_tracer_diffMode( - self, async_w3: "AsyncWeb3", txn_hash_with_log: HexStr + self, async_w3: "AsyncWeb3[Any]", txn_hash_with_log: HexStr ) -> None: result = cast( DiffModeTrace, @@ -60,7 +61,7 @@ async def test_async_geth_debug_trace_transaction_prestate_tracer_diffMode( @pytest.mark.asyncio async def test_async_geth_debug_trace_transaction_prestate_tracer( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", txn_hash_with_log: HexStr, async_block_with_txn_with_log: BlockData, ) -> None: diff --git a/web3/_utils/module_testing/go_ethereum_txpool_module.py b/web3/_utils/module_testing/go_ethereum_txpool_module.py index 9274a740ec..24a205b5c8 100644 --- a/web3/_utils/module_testing/go_ethereum_txpool_module.py +++ b/web3/_utils/module_testing/go_ethereum_txpool_module.py @@ -1,4 +1,7 @@ import pytest +from typing import ( + Any, +) from web3 import ( AsyncWeb3, @@ -8,17 +11,17 @@ class GoEthereumAsyncTxPoolModuleTest: @pytest.mark.asyncio - async def test_async_geth_txpool_inspect(self, async_w3: "AsyncWeb3") -> None: + async def test_async_geth_txpool_inspect(self, async_w3: "AsyncWeb3[Any]") -> None: test_data = await async_w3.geth.txpool.inspect() assert "pending" in test_data @pytest.mark.asyncio - async def test_async_geth_txpool_content(self, async_w3: "AsyncWeb3") -> None: + async def test_async_geth_txpool_content(self, async_w3: "AsyncWeb3[Any]") -> None: test_data = await async_w3.geth.txpool.content() assert "pending" in test_data @pytest.mark.asyncio - async def test_async_geth_txpool_status(self, async_w3: "AsyncWeb3") -> None: + async def test_async_geth_txpool_status(self, async_w3: "AsyncWeb3[Any]") -> None: test_data = await async_w3.geth.txpool.status() assert "pending" in test_data diff --git a/web3/_utils/module_testing/net_module.py b/web3/_utils/module_testing/net_module.py index 9baf1314ed..ca16927c9b 100644 --- a/web3/_utils/module_testing/net_module.py +++ b/web3/_utils/module_testing/net_module.py @@ -1,6 +1,7 @@ import pytest from typing import ( TYPE_CHECKING, + Any, ) from eth_utils import ( @@ -36,20 +37,20 @@ def test_net_peer_count(self, w3: "Web3") -> None: class AsyncNetModuleTest: @pytest.mark.asyncio - async def test_net_version(self, async_w3: "AsyncWeb3") -> None: + async def test_net_version(self, async_w3: "AsyncWeb3[Any]") -> None: version = await async_w3.net.version assert is_string(version) assert version.isdigit() @pytest.mark.asyncio - async def test_net_listening(self, async_w3: "AsyncWeb3") -> None: + async def test_net_listening(self, async_w3: "AsyncWeb3[Any]") -> None: listening = await async_w3.net.listening assert is_boolean(listening) @pytest.mark.asyncio - async def test_net_peer_count(self, async_w3: "AsyncWeb3") -> None: + async def test_net_peer_count(self, async_w3: "AsyncWeb3[Any]") -> None: peer_count = await async_w3.net.peer_count assert is_integer(peer_count) diff --git a/web3/_utils/module_testing/persistent_connection_provider.py b/web3/_utils/module_testing/persistent_connection_provider.py index d1874629bb..d739730c1c 100644 --- a/web3/_utils/module_testing/persistent_connection_provider.py +++ b/web3/_utils/module_testing/persistent_connection_provider.py @@ -173,7 +173,7 @@ async def idle_handler( async def emit_contract_event( - async_w3: AsyncWeb3, + async_w3: "AsyncWeb3[Any]", acct: ChecksumAddress, contract_function: "AsyncContractFunction", args: Any = (), @@ -186,7 +186,7 @@ async def emit_contract_event( async def log_indexed_and_non_indexed_args_task( - async_w3: AsyncWeb3, + async_w3: "AsyncWeb3[Any]", async_emitter_contract: "AsyncContract", acct: ChecksumAddress, delay: float = 0.1, @@ -226,14 +226,14 @@ async def clean_up_task(task: "asyncio.Task[Any]") -> None: class PersistentConnectionProviderTest: @pytest.fixture(autouse=True) - def clear_caches(self, async_w3: AsyncWeb3) -> Generator[None, None, None]: + def clear_caches(self, async_w3: "AsyncWeb3[Any]") -> Generator[None, None, None]: yield async_w3.provider._request_processor.clear_caches() async_w3.subscription_manager.total_handler_calls = 0 @staticmethod async def seed_transactions_to_geth( - async_w3: AsyncWeb3, + async_w3: "AsyncWeb3[Any]", acct: ChecksumAddress, num_txs: int = 1, delay: float = 0.1, @@ -305,7 +305,7 @@ async def send_tx() -> None: ) async def test_async_eth_subscribe_syncing_mocked( self, - async_w3: AsyncWeb3, + async_w3: "AsyncWeb3[Any]", subscription_params: Tuple[Any, ...], ws_subscription_response: Dict[str, Any], expected_formatted_result: Any, @@ -336,7 +336,9 @@ async def test_async_eth_subscribe_syncing_mocked( ) @pytest.mark.asyncio - async def test_async_eth_subscribe_new_heads(self, async_w3: AsyncWeb3) -> None: + async def test_async_eth_subscribe_new_heads( + self, async_w3: "AsyncWeb3[Any]" + ) -> None: sub_id = await async_w3.eth.subscribe("newHeads") assert is_hexstr(sub_id) @@ -355,7 +357,7 @@ async def test_async_eth_subscribe_new_heads(self, async_w3: AsyncWeb3) -> None: @pytest.mark.asyncio async def test_async_eth_subscribe_creates_and_handles_new_heads_subscription_type( self, - async_w3: AsyncWeb3, + async_w3: "AsyncWeb3[Any]", ) -> None: sub_manager = async_w3.subscription_manager new_heads_handler_test = SubscriptionHandlerTest() @@ -382,7 +384,7 @@ async def test_async_eth_subscribe_creates_and_handles_new_heads_subscription_ty @pytest.mark.asyncio async def test_async_eth_subscribe_process_pending_tx_true( self, - async_w3: AsyncWeb3, + async_w3: "AsyncWeb3[Any]", ) -> None: sub_id = await async_w3.eth.subscribe("newPendingTransactions", True) assert is_hexstr(sub_id) @@ -425,7 +427,7 @@ async def test_async_eth_subscribe_process_pending_tx_true( @pytest.mark.asyncio async def test_async_eth_subscribe_and_process_pending_tx_false( self, - async_w3: AsyncWeb3, + async_w3: "AsyncWeb3[Any]", ) -> None: sub_id = await async_w3.eth.subscribe("newPendingTransactions") assert is_hexstr(sub_id) @@ -462,7 +464,7 @@ async def test_async_eth_subscribe_and_process_pending_tx_false( @pytest.mark.asyncio async def test_async_eth_subscribe_creates_and_handles_pending_tx_subscription_type( self, - async_w3: AsyncWeb3, + async_w3: "AsyncWeb3[Any]", ) -> None: sub_manager = async_w3.subscription_manager pending_tx_handler_test = SubscriptionHandlerTest() @@ -499,7 +501,7 @@ async def test_async_eth_subscribe_creates_and_handles_pending_tx_subscription_t @pytest.mark.asyncio async def test_async_eth_subscribe_and_process_logs( - self, async_w3: AsyncWeb3, async_emitter_contract: "AsyncContract" + self, async_w3: "AsyncWeb3[Any]", async_emitter_contract: "AsyncContract" ) -> None: event = async_emitter_contract.events.LogIndexedAndNotIndexed event_topic = async_w3.keccak(text=event.abi_element_identifier).to_0x_hex() @@ -538,7 +540,7 @@ async def test_async_eth_subscribe_and_process_logs( @pytest.mark.asyncio async def test_async_eth_subscribe_creates_and_handles_logs_subscription_type( self, - async_w3: AsyncWeb3, + async_w3: "AsyncWeb3[Any]", async_emitter_contract: "AsyncContract", ) -> None: sub_manager = async_w3.subscription_manager @@ -658,7 +660,7 @@ async def test_async_eth_subscribe_creates_and_handles_logs_subscription_type( ) async def test_async_logs_subscription_with_and_or_topic_patterns( self, - async_w3: AsyncWeb3, + async_w3: "AsyncWeb3[Any]", async_emitter_contract: "AsyncContract", topics: Sequence[TopicFilter], ) -> None: @@ -691,7 +693,7 @@ async def test_async_logs_subscription_with_and_or_topic_patterns( @pytest.mark.asyncio async def test_async_extradata_poa_middleware_on_eth_subscription( self, - async_w3: AsyncWeb3, + async_w3: "AsyncWeb3[Any]", ) -> None: async_w3.middleware_onion.inject( ExtraDataToPOAMiddleware, "poa_middleware", layer=0 @@ -734,7 +736,7 @@ async def test_async_extradata_poa_middleware_on_eth_subscription( @pytest.mark.asyncio async def test_asyncio_gather_for_multiple_requests_matches_the_responses( self, - async_w3: AsyncWeb3, + async_w3: "AsyncWeb3[Any]", ) -> None: ( latest, @@ -770,7 +772,7 @@ async def test_asyncio_gather_for_multiple_requests_matches_the_responses( assert chain_id == chain_id2 == chain_id3 == 131277322940537 @pytest.mark.asyncio - async def test_async_public_socket_api(self, async_w3: AsyncWeb3) -> None: + async def test_async_public_socket_api(self, async_w3: "AsyncWeb3[Any]") -> None: # clear all caches and queues async_w3.provider._request_processor.clear_caches() @@ -799,7 +801,7 @@ async def test_async_public_socket_api(self, async_w3: AsyncWeb3) -> None: @pytest.mark.asyncio async def test_async_subscription_manager_subscribes_to_many_subscriptions( - self, async_w3: AsyncWeb3, async_emitter_contract: "AsyncContract" + self, async_w3: "AsyncWeb3[Any]", async_emitter_contract: "AsyncContract" ) -> None: sub_manager = async_w3.subscription_manager @@ -862,7 +864,9 @@ async def test_async_subscription_manager_subscribes_to_many_subscriptions( await clean_up_task(emit_event_task) @pytest.mark.asyncio - async def test_subscription_handler_context(self, async_w3: AsyncWeb3) -> None: + async def test_subscription_handler_context( + self, async_w3: "AsyncWeb3[Any]" + ) -> None: base_url = "http://localhost:1337" async_beacon = AsyncBeacon(base_url) handler_test = SubscriptionHandlerTest() @@ -910,7 +914,7 @@ async def test_sub_handler( @pytest.mark.asyncio async def test_subscriptions_with_handler_and_without( - self, async_w3: AsyncWeb3 + self, async_w3: "AsyncWeb3[Any]" ) -> None: handler_test = SubscriptionHandlerTest() stream_passed = False @@ -959,7 +963,7 @@ async def handle_subscription_stream() -> None: @pytest.mark.asyncio async def test_handle_subscriptions_breaks_on_unsubscribe( self, - async_w3: AsyncWeb3, + async_w3: "AsyncWeb3[Any]", ) -> None: async def unsubscribe_subs( subs: List[Union[NewHeadsSubscription, LogsSubscription]], @@ -987,7 +991,7 @@ async def unsubscribe_subs( @pytest.mark.asyncio async def test_run_forever_starts_with_0_subs_and_runs_until_task_cancelled( - self, async_w3: AsyncWeb3 + self, async_w3: "AsyncWeb3[Any]" ) -> None: sub_manager = async_w3.subscription_manager assert_no_subscriptions_left(sub_manager._subscription_container) diff --git a/web3/_utils/module_testing/utils.py b/web3/_utils/module_testing/utils.py index c6c5987493..fee665d045 100644 --- a/web3/_utils/module_testing/utils.py +++ b/web3/_utils/module_testing/utils.py @@ -97,7 +97,7 @@ def _iter_responses(): def __init__( self, - w3: Union["AsyncWeb3", "Web3"], + w3: Union["AsyncWeb3[Any]", "Web3"], mock_results: Dict[Union["RPCEndpoint", str], Any] = None, mock_errors: Dict[Union["RPCEndpoint", str], Any] = None, mock_responses: Dict[Union["RPCEndpoint", str], Any] = None, @@ -131,8 +131,9 @@ def __enter__(self) -> "Self": return self def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None: - # mypy error: Cannot assign to a method - self.w3.provider.make_request = self._make_request # type: ignore[assignment] + self.w3.provider.make_request = ( # type: ignore[method-assign] + self._make_request + ) # reset request func cache to re-build request_func with original make_request self.w3.provider._request_func_cache = (None, None) @@ -204,7 +205,7 @@ async def __aenter__(self) -> "Self": async def __aexit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None: if not isinstance(self.w3.provider, PersistentConnectionProvider): # mypy error: Cannot assign to a method - self.w3.provider.make_request = self._make_request # type: ignore[assignment] # noqa: E501 + self.w3.provider.make_request = self._make_request # type: ignore[method-assign] # noqa: E501 # reset request func cache to re-build request_func w/ original make_request self.w3.provider._request_func_cache = (None, None) else: @@ -261,7 +262,7 @@ async def _async_build_mock_result( async def _async_mock_request_handler( self, method: "RPCEndpoint", params: Any ) -> "RPCResponse": - self.w3 = cast("AsyncWeb3", self.w3) + self.w3 = cast("AsyncWeb3[Any]", self.w3) self._make_request = cast("AsyncMakeRequestFn", self._make_request) if all( method not in mock_dict @@ -299,7 +300,7 @@ async def _async_mock_send_handler( async def _async_mock_recv_handler( self, rpc_request: "RPCRequest" ) -> "RPCResponse": - self.w3 = cast("AsyncWeb3", self.w3) + self.w3 = cast("AsyncWeb3[Any]", self.w3) method = rpc_request["method"] request_id = rpc_request["id"] if all( diff --git a/web3/_utils/module_testing/web3_module.py b/web3/_utils/module_testing/web3_module.py index 04ad2d402f..ef77368b86 100644 --- a/web3/_utils/module_testing/web3_module.py +++ b/web3/_utils/module_testing/web3_module.py @@ -565,13 +565,15 @@ class AsyncWeb3ModuleTest(Web3ModuleTest): # an asynchronous test should have the exact same name. @pytest.mark.asyncio - async def test_web3_client_version(self, async_w3: AsyncWeb3) -> None: # type: ignore[override] # noqa: E501 + async def test_web3_client_version( + self, async_w3: AsyncWeb3[Any] + ) -> None: # noqa: E501 client_version = await async_w3.client_version self._check_web3_client_version(client_version) @pytest.mark.asyncio - async def test_batch_requests( # type: ignore[override] - self, async_w3: AsyncWeb3, async_math_contract: "AsyncContract" + async def test_batch_requests( + self, async_w3: AsyncWeb3[Any], async_math_contract: "AsyncContract" ) -> None: async with async_w3.batch_requests() as batch: batch.add(async_w3.eth.get_block(6)) @@ -638,8 +640,10 @@ async def test_batch_requests( # type: ignore[override] assert last_three_responses[2]["number"] == 5 @pytest.mark.asyncio - async def test_batch_requests_initialized_as_object( # type: ignore[override] - self, async_w3: AsyncWeb3, async_math_contract: "AsyncContract" # type: ignore[override] # noqa: E501 + async def test_batch_requests_initialized_as_object( + self, + async_w3: AsyncWeb3[Any], + async_math_contract: "AsyncContract", # noqa: E501 ) -> None: batch = async_w3.batch_requests() batch.add(async_w3.eth.get_block(1)) @@ -686,7 +690,9 @@ async def test_batch_requests_initialized_as_object( # type: ignore[override] assert cast(BlockData, b4)["number"] == 4 @pytest.mark.asyncio - async def test_batch_requests_clear(self, async_w3: AsyncWeb3) -> None: # type: ignore[override] # noqa: E501 + async def test_batch_requests_clear( + self, async_w3: AsyncWeb3[Any] + ) -> None: # noqa: E501 async with async_w3.batch_requests() as batch: batch.add(async_w3.eth.get_block(1)) batch.add(async_w3.eth.get_block(2)) @@ -715,7 +721,9 @@ async def test_batch_requests_clear(self, async_w3: AsyncWeb3) -> None: # type: assert cast(BlockData, r3)["number"] == 6 @pytest.mark.asyncio - async def test_batch_requests_cancel(self, async_w3: AsyncWeb3) -> None: # type: ignore[override] # noqa: E501 + async def test_batch_requests_cancel( + self, async_w3: AsyncWeb3[Any] + ) -> None: # noqa: E501 # as context manager async with async_w3.batch_requests() as batch: batch.add(async_w3.eth.get_block(1)) @@ -755,8 +763,10 @@ async def test_batch_requests_cancel(self, async_w3: AsyncWeb3) -> None: # type assert isinstance(block_num, int) @pytest.mark.asyncio - async def test_batch_requests_raises_for_common_unsupported_methods( # type: ignore[override] # noqa: E501 - self, async_w3: AsyncWeb3, async_math_contract: "AsyncContract" # type: ignore[override] # noqa: E501 + async def test_batch_requests_raises_for_common_unsupported_methods( # noqa: E501 + self, + async_w3: AsyncWeb3[Any], + async_math_contract: "AsyncContract", # noqa: E501 ) -> None: async with async_w3.batch_requests() as batch: with pytest.raises(MethodNotSupported, match="eth_sendTransaction"): @@ -779,8 +789,8 @@ async def test_batch_requests_raises_for_common_unsupported_methods( # type: ig await batch.async_execute() @pytest.mark.asyncio - async def test_batch_requests_concurrently_with_regular_requests( # type: ignore[override] # noqa: E501 - self, async_w3: AsyncWeb3 # type: ignore[override] + async def test_batch_requests_concurrently_with_regular_requests( # noqa: E501 + self, async_w3: AsyncWeb3[Any] ) -> None: responses = [] batch_response = [] diff --git a/web3/_utils/normalizers.py b/web3/_utils/normalizers.py index 6e70235d93..98683fa4bd 100644 --- a/web3/_utils/normalizers.py +++ b/web3/_utils/normalizers.py @@ -72,7 +72,7 @@ def implicitly_identity( - to_wrap: Callable[[TypeStr, Any], Any] + to_wrap: Callable[[TypeStr, Any], Any], ) -> Callable[[TypeStr, Any], Tuple[TypeStr, Any]]: @functools.wraps(to_wrap) def wrapper(type_str: TypeStr, data: Any) -> Tuple[TypeStr, Any]: @@ -112,7 +112,7 @@ def decode_abi_strings(type_str: TypeStr, data: Any) -> Tuple[TypeStr, str]: def parse_basic_type_str( - old_normalizer: Callable[[BasicType, TypeStr, Any], Tuple[TypeStr, Any]] + old_normalizer: Callable[[BasicType, TypeStr, Any], Tuple[TypeStr, Any]], ) -> Callable[[TypeStr, Any], Tuple[TypeStr, Any]]: """ Modifies a normalizer to automatically parse the incoming type string. If @@ -283,7 +283,7 @@ def normalize_bytecode(bytecode: Optional[bytes]) -> Union[HexBytes, None]: async def async_abi_ens_resolver( - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", type_str: TypeStr, val: Any, ) -> Tuple[TypeStr, Any]: diff --git a/web3/_utils/transactions.py b/web3/_utils/transactions.py index e2ffc7b502..6feeb75dab 100644 --- a/web3/_utils/transactions.py +++ b/web3/_utils/transactions.py @@ -1,6 +1,7 @@ import math from typing import ( TYPE_CHECKING, + Any, Dict, List, Literal, @@ -230,7 +231,7 @@ def assert_valid_transaction_params(transaction_params: TxParams) -> None: def prepare_replacement_transaction( - w3: Union["Web3", "AsyncWeb3"], + w3: Union["Web3", "AsyncWeb3[Any]"], original_transaction: TxData, replacement_transaction: TxParams, gas_multiplier: float = 1.125, diff --git a/web3/contract/async_contract.py b/web3/contract/async_contract.py index 53cb442f61..4ae755aea0 100644 --- a/web3/contract/async_contract.py +++ b/web3/contract/async_contract.py @@ -103,7 +103,7 @@ class AsyncContractEvent(BaseContractEvent): # mypy types - w3: "AsyncWeb3" + w3: "AsyncWeb3[Any]" @combomethod async def get_logs( @@ -238,14 +238,14 @@ def build_filter(self) -> AsyncEventFilterBuilder: class AsyncContractEvents(BaseContractEvents[AsyncContractEvent]): def __init__( - self, abi: ABI, w3: "AsyncWeb3", address: Optional[ChecksumAddress] = None + self, abi: ABI, w3: "AsyncWeb3[Any]", address: Optional[ChecksumAddress] = None ) -> None: super().__init__(abi, w3, AsyncContractEvent, address) class AsyncContractFunction(BaseContractFunction): # mypy types - w3: "AsyncWeb3" + w3: "AsyncWeb3[Any]" async def call( self, @@ -357,7 +357,7 @@ async def build_transaction( @staticmethod def get_fallback_function( abi: ABI, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", address: Optional[ChecksumAddress] = None, ) -> "AsyncContractFunction": if abi and fallback_func_abi_exists(abi): @@ -373,7 +373,7 @@ def get_fallback_function( @staticmethod def get_receive_function( abi: ABI, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", address: Optional[ChecksumAddress] = None, ) -> "AsyncContractFunction": if abi and receive_func_abi_exists(abi): @@ -391,7 +391,7 @@ class AsyncContractFunctions(BaseContractFunctions[AsyncContractFunction]): def __init__( self, abi: ABI, - w3: "AsyncWeb3", + w3: "AsyncWeb3[Any]", address: Optional[ChecksumAddress] = None, decode_tuples: Optional[bool] = False, ) -> None: @@ -403,7 +403,7 @@ class AsyncContract(BaseContract): caller: "AsyncContractCaller" = None # mypy types - w3: "AsyncWeb3" + w3: "AsyncWeb3[Any]" #: Instance of :class:`ContractEvents` presenting available Event ABIs events: AsyncContractEvents = None @@ -447,7 +447,7 @@ def __init__(self, address: Optional[ChecksumAddress] = None) -> None: @classmethod def factory( - cls, w3: "AsyncWeb3", class_name: Optional[str] = None, **kwargs: Any + cls, w3: "AsyncWeb3[Any]", class_name: Optional[str] = None, **kwargs: Any ) -> Type[Self]: kwargs["w3"] = w3 @@ -519,7 +519,7 @@ def constructor(cls, *args: Any, **kwargs: Any) -> "AsyncContractConstructor": def find_functions_by_identifier( cls, contract_abi: ABI, - w3: "AsyncWeb3", + w3: "AsyncWeb3[Any]", address: ChecksumAddress, callable_check: Callable[..., Any], ) -> List["AsyncContractFunction"]: @@ -540,7 +540,7 @@ def get_function_by_identifier( def find_events_by_identifier( cls, contract_abi: ABI, - w3: "AsyncWeb3", + w3: "AsyncWeb3[Any]", address: ChecksumAddress, callable_check: Callable[..., Any], ) -> List["AsyncContractEvent"]: @@ -557,12 +557,12 @@ def get_event_by_identifier( class AsyncContractCaller(BaseContractCaller): # mypy types - w3: "AsyncWeb3" + w3: "AsyncWeb3[Any]" def __init__( self, abi: ABI, - w3: "AsyncWeb3", + w3: "AsyncWeb3[Any]", address: ChecksumAddress, transaction: Optional[TxParams] = None, block_identifier: BlockIdentifier = None, @@ -613,7 +613,7 @@ def __call__( class AsyncContractConstructor(BaseContractConstructor): # mypy types - w3: "AsyncWeb3" + w3: "AsyncWeb3[Any]" @combomethod async def transact(self, transaction: Optional[TxParams] = None) -> HexBytes: diff --git a/web3/contract/base_contract.py b/web3/contract/base_contract.py index 6e9c3c9a04..53134ab6e9 100644 --- a/web3/contract/base_contract.py +++ b/web3/contract/base_contract.py @@ -169,7 +169,7 @@ class BaseContractEvent: name: str = None abi_element_identifier: ABIElementIdentifier = None signature: str = None - w3: Union["Web3", "AsyncWeb3"] = None + w3: Union["Web3", "AsyncWeb3[Any]"] = None contract_abi: ABI = None abi: ABIEvent = None argument_names: Tuple[str, ...] = tuple() @@ -477,7 +477,7 @@ class BaseContractEvents(Generic[TContractEvent]): def __init__( self, abi: ABI, - w3: Union["Web3", "AsyncWeb3"], + w3: Union["Web3", "AsyncWeb3[Any]"], contract_event_type: Type[TContractEvent], address: Optional[ChecksumAddress] = None, ) -> None: @@ -569,7 +569,7 @@ class BaseContractFunction: name: str = None signature: str = None abi_element_identifier: ABIElementIdentifier = None - w3: Union["Web3", "AsyncWeb3"] = None + w3: Union["Web3", "AsyncWeb3[Any]"] = None contract_abi: ABI = None abi: ABIFunction = None transaction: TxParams = None @@ -894,7 +894,7 @@ class BaseContractFunctions(Generic[TContractFn]): def __init__( self, abi: ABI, - w3: Union["Web3", "AsyncWeb3"], + w3: Union["Web3", "AsyncWeb3[Any]"], contract_function_class: Type[TContractFn], address: Optional[ChecksumAddress] = None, decode_tuples: Optional[bool] = False, @@ -1000,8 +1000,7 @@ class BaseContract: * Deploy a new smart contract using :py:meth:`Contract.constructor.transact()` """ - # set during class construction - w3: Union["Web3", "AsyncWeb3"] = None + w3: Union["Web3", "AsyncWeb3[Any]"] = None # instance level properties address: ChecksumAddress = None @@ -1286,7 +1285,7 @@ def get_event_by_topic(self, topic: HexStr) -> "BaseContractEvent": def find_functions_by_identifier( cls, contract_abi: ABI, - w3: Union["Web3", "AsyncWeb3"], + w3: Union["Web3", "AsyncWeb3[Any]"], address: ChecksumAddress, callable_check: Callable[..., Any], ) -> List[Any]: @@ -1306,7 +1305,7 @@ def get_function_by_identifier( def find_events_by_identifier( cls, contract_abi: ABI, - w3: Union["Web3", "AsyncWeb3"], + w3: Union["Web3", "AsyncWeb3[Any]"], address: ChecksumAddress, callable_check: Callable[..., Any], ) -> List[Any]: @@ -1325,7 +1324,7 @@ def get_event_by_identifier( @staticmethod def get_fallback_function( abi: ABI, - w3: Union["Web3", "AsyncWeb3"], + w3: Union["Web3", "AsyncWeb3[Any]"], function_type: Type["BaseContractFunction"], address: Optional[ChecksumAddress] = None, ) -> "BaseContractFunction": @@ -1345,7 +1344,7 @@ def get_fallback_function( @staticmethod def get_receive_function( abi: ABI, - w3: Union["Web3", "AsyncWeb3"], + w3: Union["Web3", "AsyncWeb3[Any]"], function_type: Type["BaseContractFunction"], address: Optional[ChecksumAddress] = None, ) -> "BaseContractFunction": @@ -1469,7 +1468,7 @@ class BaseContractCaller: def __init__( self, abi: ABI, - w3: Union["Web3", "AsyncWeb3"], + w3: Union["Web3", "AsyncWeb3[Any]"], address: ChecksumAddress, decode_tuples: Optional[bool] = False, ) -> None: @@ -1542,7 +1541,7 @@ class BaseContractConstructor: def __init__( self, - w3: Union["Web3", "AsyncWeb3"], + w3: Union["Web3", "AsyncWeb3[Any]"], abi: ABI, bytecode: HexStr, *args: Any, diff --git a/web3/contract/utils.py b/web3/contract/utils.py index 3fc26be753..d1d072a0f7 100644 --- a/web3/contract/utils.py +++ b/web3/contract/utils.py @@ -85,7 +85,7 @@ @curry def format_contract_call_return_data_curried( - async_w3: Union["AsyncWeb3", "Web3"], + async_w3: Union["AsyncWeb3[Any]", "Web3"], decode_tuples: bool, fn_abi: ABICallable, abi_element_identifier: ABIElementIdentifier, @@ -332,7 +332,7 @@ def build_transaction_for_function( def find_functions_by_identifier( contract_abi: ABI, - w3: Union["Web3", "AsyncWeb3"], + w3: Union["Web3", "AsyncWeb3[Any]"], address: ChecksumAddress, callable_check: Callable[..., Any], function_type: Type[TContractFn], @@ -376,7 +376,7 @@ def get_function_by_identifier( def find_events_by_identifier( contract_abi: ABI, - w3: Union["Web3", "AsyncWeb3"], + w3: Union["Web3", "AsyncWeb3[Any]"], address: ChecksumAddress, callable_check: Callable[..., Any], event_type: Type[TContractEvent], @@ -418,7 +418,7 @@ def get_event_by_identifier( async def async_call_contract_function( - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", address: ChecksumAddress, normalizers: Tuple[Callable[..., Any], ...], abi_element_identifier: ABIElementIdentifier, @@ -534,7 +534,7 @@ async def async_call_contract_function( async def async_transact_with_contract_function( address: ChecksumAddress, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", abi_element_identifier: Optional[ABIElementIdentifier] = None, transaction: Optional[TxParams] = None, contract_abi: Optional[ABI] = None, @@ -563,7 +563,7 @@ async def async_transact_with_contract_function( async def async_estimate_gas_for_function( address: ChecksumAddress, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", abi_element_identifier: Optional[ABIElementIdentifier] = None, transaction: Optional[TxParams] = None, contract_abi: Optional[ABI] = None, @@ -597,7 +597,7 @@ async def async_estimate_gas_for_function( async def async_build_transaction_for_function( address: ChecksumAddress, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", abi_element_identifier: Optional[ABIElementIdentifier] = None, transaction: Optional[TxParams] = None, contract_abi: Optional[ABI] = None, diff --git a/web3/eth/async_eth.py b/web3/eth/async_eth.py index 603db9b3bd..1a17a71e68 100644 --- a/web3/eth/async_eth.py +++ b/web3/eth/async_eth.py @@ -119,7 +119,7 @@ class AsyncEth(BaseEth): # mypy types - w3: "AsyncWeb3" + w3: "AsyncWeb3[Any]" is_async = True diff --git a/web3/gas_strategies/time_based.py b/web3/gas_strategies/time_based.py index 4cd3e34f53..5a847bd0ec 100644 --- a/web3/gas_strategies/time_based.py +++ b/web3/gas_strategies/time_based.py @@ -104,7 +104,7 @@ def _get_raw_miner_data( def _aggregate_miner_data( - raw_data: Iterable[Tuple[ChecksumAddress, HexBytes, Wei]] + raw_data: Iterable[Tuple[ChecksumAddress, HexBytes, Wei]], ) -> Iterable[MinerData]: data_by_miner = groupby(0, raw_data) diff --git a/web3/main.py b/web3/main.py index c118c0d5e1..ee084d9bcc 100644 --- a/web3/main.py +++ b/web3/main.py @@ -37,10 +37,12 @@ Callable, Dict, Generator, + Generic, List, Optional, Sequence, Type, + TypeVar, Union, cast, ) @@ -359,7 +361,7 @@ def batch_requests( def _validate_provider( - w3: Union["Web3", "AsyncWeb3"], + w3: Union["Web3", "AsyncWeb3[Any]"], provider: Optional[Union[BaseProvider, AsyncBaseProvider]], ) -> None: if provider is not None: @@ -447,7 +449,10 @@ def ens(self, new_ens: Union[ENS, "Empty"]) -> None: # -- async -- # -class AsyncWeb3(BaseWeb3): +AsyncProviderT = TypeVar("AsyncProviderT", bound=AsyncBaseProvider) + + +class AsyncWeb3(BaseWeb3, Generic[AsyncProviderT]): # mypy Types eth: AsyncEth net: AsyncNet @@ -460,7 +465,7 @@ class AsyncWeb3(BaseWeb3): def __init__( self, - provider: Optional[AsyncBaseProvider] = None, + provider: Optional[AsyncProviderT] = None, middleware: Optional[Sequence[Any]] = None, modules: Optional[Dict[str, Union[Type[Module], Sequence[Any]]]] = None, external_modules: Optional[ @@ -486,11 +491,11 @@ async def is_connected(self, show_traceback: bool = False) -> bool: return await self.provider.is_connected(show_traceback) @property - def provider(self) -> AsyncBaseProvider: - return cast(AsyncBaseProvider, self.manager.provider) + def provider(self) -> AsyncProviderT: + return cast(AsyncProviderT, self.manager.provider) @provider.setter - def provider(self, provider: AsyncBaseProvider) -> None: + def provider(self, provider: AsyncProviderT) -> None: self.manager.provider = provider @property diff --git a/web3/manager.py b/web3/manager.py index dc3d663bf9..dcfef135fd 100644 --- a/web3/manager.py +++ b/web3/manager.py @@ -105,7 +105,7 @@ class RequestManager: def __init__( self, - w3: Union["AsyncWeb3", "Web3"], + w3: Union["AsyncWeb3[Any]", "Web3"], provider: Optional[Union["BaseProvider", "AsyncBaseProvider"]] = None, middleware: Optional[Sequence[Tuple[Middleware, str]]] = None, ) -> None: @@ -167,7 +167,8 @@ async def _coro_make_request( ) -> RPCResponse: provider = cast("AsyncBaseProvider", self.provider) request_func = await provider.request_func( - cast("AsyncWeb3", self.w3), cast("MiddlewareOnion", self.middleware_onion) + cast("AsyncWeb3[Any]", self.w3), + cast("MiddlewareOnion", self.middleware_onion), ) self.logger.debug("Making request. Method: %s", method) return await request_func(method, params) @@ -299,7 +300,7 @@ async def _async_make_batch_request( """ provider = cast(AsyncJSONBaseProvider, self.provider) request_func = await provider.batch_request_func( - cast("AsyncWeb3", self.w3), + cast("AsyncWeb3[Any]", self.w3), cast("MiddlewareOnion", self.middleware_onion), ) # since we add items to the batch without awaiting, we unpack the coroutines @@ -336,7 +337,7 @@ async def _async_send_batch( "can send batch requests." ) send_func = await self._provider.send_batch_func( - cast("AsyncWeb3", self.w3), + cast("AsyncWeb3[Any]", self.w3), cast("MiddlewareOnion", self.middleware_onion), ) self.logger.debug( @@ -355,7 +356,7 @@ async def _async_recv_batch(self, requests: List[RPCRequest]) -> List[RPCRespons "can receive batch requests." ) recv_func = await self._provider.recv_batch_func( - cast("AsyncWeb3", self.w3), + cast("AsyncWeb3[Any]", self.w3), cast("MiddlewareOnion", self.middleware_onion), ) self.logger.debug( @@ -457,7 +458,7 @@ async def socket_request( async def send(self, method: RPCEndpoint, params: Any) -> RPCRequest: provider = cast(PersistentConnectionProvider, self._provider) - async_w3 = cast("AsyncWeb3", self.w3) + async_w3 = cast("AsyncWeb3[Any]", self.w3) middleware_onion = cast("MiddlewareOnion", self.middleware_onion) send_func = await provider.send_func( async_w3, @@ -475,7 +476,7 @@ async def send(self, method: RPCEndpoint, params: Any) -> RPCRequest: async def recv_for_request(self, rpc_request: RPCRequest) -> RPCResponse: provider = cast(PersistentConnectionProvider, self._provider) - async_w3 = cast("AsyncWeb3", self.w3) + async_w3 = cast("AsyncWeb3[Any]", self.w3) middleware_onion = cast("MiddlewareOnion", self.middleware_onion) recv_func = await provider.recv_func( async_w3, @@ -523,7 +524,7 @@ async def _message_stream( "Only providers that maintain an open, persistent connection " "can listen to streams." ) - async_w3 = cast("AsyncWeb3", self.w3) + async_w3 = cast("AsyncWeb3[Any]", self.w3) if self._provider._message_listener_task is None: raise ProviderConnectionError( diff --git a/web3/middleware/__init__.py b/web3/middleware/__init__.py index 512b27ecf7..78a394ef50 100644 --- a/web3/middleware/__init__.py +++ b/web3/middleware/__init__.py @@ -78,7 +78,7 @@ def combine_middleware( async def async_combine_middleware( middleware: Sequence[Middleware], - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", provider_request_fn: AsyncMakeRequestFn, ) -> Callable[..., Coroutine[Any, Any, "RPCResponse"]]: """ diff --git a/web3/middleware/base.py b/web3/middleware/base.py index 5f968f826d..c5498ad252 100644 --- a/web3/middleware/base.py +++ b/web3/middleware/base.py @@ -35,9 +35,9 @@ class Web3Middleware: but instead inherited from. """ - _w3: Union["AsyncWeb3", "Web3"] + _w3: Union["AsyncWeb3[Any]", "Web3"] - def __init__(self, w3: Union["AsyncWeb3", "Web3"]) -> None: + def __init__(self, w3: Union["AsyncWeb3[Any]", "Web3"]) -> None: self._w3 = w3 def __hash__(self) -> int: @@ -61,7 +61,7 @@ def wrap_make_batch_request( self, make_batch_request: "MakeBatchRequestFn" ) -> "MakeBatchRequestFn": def middleware( - requests_info: List[Tuple["RPCEndpoint", Any]] + requests_info: List[Tuple["RPCEndpoint", Any]], ) -> Union[List["RPCResponse"], "RPCResponse"]: req_processed = [ self.request_processor(method, params) @@ -106,7 +106,7 @@ async def async_wrap_make_batch_request( self, make_batch_request: "AsyncMakeBatchRequestFn" ) -> "AsyncMakeBatchRequestFn": async def middleware( - requests_info: List[Tuple["RPCEndpoint", Any]] + requests_info: List[Tuple["RPCEndpoint", Any]], ) -> Union[List["RPCResponse"], "RPCResponse"]: req_processed = [ await self.async_request_processor(method, params) @@ -145,7 +145,7 @@ class Web3MiddlewareBuilder(Web3Middleware): @staticmethod @abstractmethod def build( - w3: Union["AsyncWeb3", "Web3"], + w3: Union["AsyncWeb3[Any]", "Web3"], *args: Any, **kwargs: Any, ) -> Web3Middleware: diff --git a/web3/middleware/buffered_gas_estimate.py b/web3/middleware/buffered_gas_estimate.py index ce810fb5b1..176f2c3cb4 100644 --- a/web3/middleware/buffered_gas_estimate.py +++ b/web3/middleware/buffered_gas_estimate.py @@ -52,7 +52,7 @@ async def async_request_processor(self, method: "RPCEndpoint", params: Any) -> A transaction = params[0] if "gas" not in transaction: gas_estimate = await async_get_buffered_gas_estimate( - cast("AsyncWeb3", self._w3), transaction + cast("AsyncWeb3[Any]", self._w3), transaction ) transaction = assoc(transaction, "gas", hex(gas_estimate)) params = (transaction,) diff --git a/web3/middleware/filter.py b/web3/middleware/filter.py index 3fd39eb8a9..0fe843bffd 100644 --- a/web3/middleware/filter.py +++ b/web3/middleware/filter.py @@ -357,7 +357,8 @@ def block_hashes_in_range( async def async_iter_latest_block( - w3: "AsyncWeb3", to_block: Optional[Union[BlockNumber, LatestBlockParam]] = None + w3: "AsyncWeb3[Any]", + to_block: Optional[Union[BlockNumber, LatestBlockParam]] = None, ) -> AsyncIterable[BlockNumber]: """ Returns a generator that dispenses the latest block, if @@ -394,7 +395,7 @@ async def async_iter_latest_block( async def async_iter_latest_block_ranges( - w3: "AsyncWeb3", + w3: "AsyncWeb3[Any]", from_block: BlockNumber, to_block: Optional[Union[BlockNumber, LatestBlockParam]] = None, ) -> AsyncIterable[Tuple[Optional[BlockNumber], Optional[BlockNumber]]]: @@ -425,7 +426,7 @@ async def async_iter_latest_block_ranges( async def async_get_logs_multipart( - w3: "AsyncWeb3", + w3: "AsyncWeb3[Any]", start_block: BlockNumber, stop_block: BlockNumber, address: Union[Address, ChecksumAddress, List[Union[Address, ChecksumAddress]]], @@ -458,7 +459,7 @@ class AsyncRequestLogs: def __init__( self, - w3: "AsyncWeb3", + w3: "AsyncWeb3[Any]", from_block: Optional[Union[BlockNumber, LatestBlockParam]] = None, to_block: Optional[Union[BlockNumber, LatestBlockParam]] = None, address: Optional[ @@ -544,7 +545,7 @@ async def get_logs(self) -> List[LogReceipt]: class AsyncRequestBlocks: - def __init__(self, w3: "AsyncWeb3") -> None: + def __init__(self, w3: "AsyncWeb3[Any]") -> None: self.w3 = w3 def __await__(self) -> Generator[Any, None, "AsyncRequestBlocks"]: @@ -569,7 +570,7 @@ async def get_filter_changes(self) -> AsyncIterator[List[Hash32]]: async def async_block_hashes_in_range( - w3: "AsyncWeb3", block_range: Tuple[BlockNumber, BlockNumber] + w3: "AsyncWeb3[Any]", block_range: Tuple[BlockNumber, BlockNumber] ) -> List[Union[None, Hash32]]: from_block, to_block = block_range if from_block is None or to_block is None: @@ -594,7 +595,7 @@ def _simulate_rpc_response_with_result(filter_id: str) -> "RPCResponse": class LocalFilterMiddleware(Web3Middleware): - def __init__(self, w3: Union["Web3", "AsyncWeb3"]): + def __init__(self, w3: Union["Web3", "AsyncWeb3[Any]"]): self.filters: Dict[str, SyncFilter] = {} self.async_filters: Dict[str, AsyncFilter] = {} self.filter_id_counter = itertools.count() @@ -660,12 +661,12 @@ async def middleware(method: "RPCEndpoint", params: Any) -> "RPCResponse": if method == RPC.eth_newFilter: _filter = await AsyncRequestLogs( - cast("AsyncWeb3", self._w3), + cast("AsyncWeb3[Any]", self._w3), **apply_key_map(FILTER_PARAMS_KEY_MAP, params[0]) ) elif method == RPC.eth_newBlockFilter: - _filter = await AsyncRequestBlocks(cast("AsyncWeb3", self._w3)) + _filter = await AsyncRequestBlocks(cast("AsyncWeb3[Any]", self._w3)) else: raise NotImplementedError(method) diff --git a/web3/middleware/formatting.py b/web3/middleware/formatting.py index f6c765ee49..ec4dfff781 100644 --- a/web3/middleware/formatting.py +++ b/web3/middleware/formatting.py @@ -100,7 +100,7 @@ def _format_response( SYNC_FORMATTERS_BUILDER = Callable[["Web3", RPCEndpoint], FormattersDict] ASYNC_FORMATTERS_BUILDER = Callable[ - ["AsyncWeb3", RPCEndpoint], Coroutine[Any, Any, FormattersDict] + ["AsyncWeb3[Any]", RPCEndpoint], Coroutine[Any, Any, FormattersDict] ] @@ -114,7 +114,7 @@ class FormattingMiddlewareBuilder(Web3MiddlewareBuilder): @staticmethod @curry def build( - w3: Union["AsyncWeb3", "Web3"], + w3: Union["Web3", "AsyncWeb3[Any]"], # formatters option: request_formatters: Optional[Formatters] = None, result_formatters: Optional[Formatters] = None, @@ -186,7 +186,7 @@ async def async_request_processor(self, method: "RPCEndpoint", params: Any) -> A formatters = merge( FORMATTER_DEFAULTS, await self.async_formatters_builder( - cast("AsyncWeb3", self._w3), method + cast("AsyncWeb3[Any]", self._w3), method ), ) self.request_formatters = formatters.pop("request_formatters") @@ -204,7 +204,7 @@ async def async_response_processor( formatters = merge( FORMATTER_DEFAULTS, await self.async_formatters_builder( - cast("AsyncWeb3", self._w3), method + cast("AsyncWeb3[Any]", self._w3), method ), ) self.result_formatters = formatters["result_formatters"] diff --git a/web3/middleware/gas_price_strategy.py b/web3/middleware/gas_price_strategy.py index 0149ec80fa..ab78df9235 100644 --- a/web3/middleware/gas_price_strategy.py +++ b/web3/middleware/gas_price_strategy.py @@ -106,7 +106,7 @@ def request_processor(self, method: RPCEndpoint, params: Any) -> Any: async def async_request_processor(self, method: RPCEndpoint, params: Any) -> Any: if method == "eth_sendTransaction": transaction = params[0] - w3 = cast("AsyncWeb3", self._w3) + w3 = cast("AsyncWeb3[Any]", self._w3) generated_gas_price = w3.eth.generate_gas_price(transaction) latest_block = await w3.eth.get_block("latest") transaction = validate_transaction_params( diff --git a/web3/middleware/names.py b/web3/middleware/names.py index e6a49363ce..8c6e690335 100644 --- a/web3/middleware/names.py +++ b/web3/middleware/names.py @@ -53,7 +53,7 @@ def _is_logs_subscription_with_optional_args(method: RPCEndpoint, params: Any) - async def async_format_all_ens_names_to_address( - async_web3: "AsyncWeb3", + async_web3: "AsyncWeb3[Any]", abi_types_for_method: Sequence[Any], data: Sequence[Any], ) -> Sequence[Any]: @@ -69,7 +69,7 @@ async def async_format_all_ens_names_to_address( async def async_apply_ens_to_address_conversion( - async_web3: "AsyncWeb3", + async_web3: "AsyncWeb3[Any]", params: Any, abi_types_for_method: Union[Sequence[str], Dict[str, str]], ) -> Any: @@ -125,7 +125,7 @@ async def async_request_processor(self, method: "RPCEndpoint", params: Any) -> A # eth_subscribe optional logs params are unique. # Handle them separately here. (formatted_dict,) = await async_apply_ens_to_address_conversion( - cast("AsyncWeb3", self._w3), + cast("AsyncWeb3[Any]", self._w3), (params[1],), { "address": "address", @@ -136,7 +136,7 @@ async def async_request_processor(self, method: "RPCEndpoint", params: Any) -> A else: params = await async_apply_ens_to_address_conversion( - cast("AsyncWeb3", self._w3), + cast("AsyncWeb3[Any]", self._w3), params, abi_types_for_method, ) diff --git a/web3/middleware/signing.py b/web3/middleware/signing.py index 3e4eafcaa9..25c6b3b9f1 100644 --- a/web3/middleware/signing.py +++ b/web3/middleware/signing.py @@ -93,7 +93,7 @@ def is_eth_key(value: Any) -> bool: @to_dict def gen_normalized_accounts( - val: Union[_PrivateKey, Collection[_PrivateKey]] + val: Union[_PrivateKey, Collection[_PrivateKey]], ) -> Iterable[Tuple[ChecksumAddress, LocalAccount]]: if isinstance( val, @@ -158,7 +158,7 @@ class SignAndSendRawMiddlewareBuilder(Web3MiddlewareBuilder): @curry def build( private_key_or_account: Union[_PrivateKey, Collection[_PrivateKey]], - w3: Union["Web3", "AsyncWeb3"], + w3: Union["Web3", "AsyncWeb3[Any]"], ) -> "SignAndSendRawMiddlewareBuilder": middleware = SignAndSendRawMiddlewareBuilder(w3) middleware._accounts = gen_normalized_accounts(private_key_or_account) @@ -199,7 +199,7 @@ async def async_request_processor(self, method: "RPCEndpoint", params: Any) -> A return method, params else: - w3 = cast("AsyncWeb3", self._w3) + w3 = cast("AsyncWeb3[Any]", self._w3) formatted_transaction = format_transaction(params[0]) filled_transaction = await async_fill_transaction_defaults( diff --git a/web3/middleware/stalecheck.py b/web3/middleware/stalecheck.py index 2b83ca2586..def8c3580f 100644 --- a/web3/middleware/stalecheck.py +++ b/web3/middleware/stalecheck.py @@ -51,7 +51,7 @@ class StalecheckMiddlewareBuilder(Web3MiddlewareBuilder): @curry def build( allowable_delay: int, - w3: Union["Web3", "AsyncWeb3"], + w3: Union["Web3", "AsyncWeb3[Any]"], skip_stalecheck_for_methods: Collection[str] = SKIP_STALECHECK_FOR_METHODS, ) -> Web3Middleware: if allowable_delay <= 0: @@ -82,7 +82,7 @@ def request_processor(self, method: "RPCEndpoint", params: Any) -> Any: async def async_request_processor(self, method: "RPCEndpoint", params: Any) -> Any: if method not in self.skip_stalecheck_for_methods: if not _is_fresh(self.cache["latest"], self.allowable_delay): - w3 = cast("AsyncWeb3", self._w3) + w3 = cast("AsyncWeb3[Any]", self._w3) latest = await w3.eth.get_block("latest") if _is_fresh(latest, self.allowable_delay): diff --git a/web3/middleware/validation.py b/web3/middleware/validation.py index e90cff8690..7496824b1f 100644 --- a/web3/middleware/validation.py +++ b/web3/middleware/validation.py @@ -121,7 +121,7 @@ def _chain_id_validator(web3_chain_id: int) -> Callable[..., Any]: def _build_formatters_dict( - request_formatters: Dict[RPCEndpoint, Any] + request_formatters: Dict[RPCEndpoint, Any], ) -> FormattersDict: return dict( request_formatters=request_formatters, @@ -149,7 +149,7 @@ def build_method_validators(w3: "Web3", method: RPCEndpoint) -> FormattersDict: async def async_build_method_validators( - async_w3: "AsyncWeb3", method: RPCEndpoint + async_w3: "AsyncWeb3[Any]", method: RPCEndpoint ) -> FormattersDict: request_formatters: Formatters = {} if RPCEndpoint(method) in METHODS_TO_VALIDATE: diff --git a/web3/module.py b/web3/module.py index 0f9d85d7bd..945530b28e 100644 --- a/web3/module.py +++ b/web3/module.py @@ -60,7 +60,7 @@ def apply_result_formatters( @curry def retrieve_request_information_for_batching( - w3: Union["AsyncWeb3", "Web3"], + w3: Union["AsyncWeb3[Any]", "Web3"], module: "Module", method: Method[Callable[..., Any]], ) -> Union[ @@ -119,7 +119,7 @@ def caller(*args: Any, **kwargs: Any) -> Union[TReturn, LogFilter]: @curry def retrieve_async_method_call_fn( - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", module: "Module", method: Method[Callable[..., Any]], ) -> Callable[ @@ -167,7 +167,7 @@ async def caller( class Module: is_async = False - def __init__(self, w3: Union["AsyncWeb3", "Web3"]) -> None: + def __init__(self, w3: Union["AsyncWeb3[Any]", "Web3"]) -> None: if self.is_async: self.retrieve_caller_fn = retrieve_async_method_call_fn(w3, self) else: diff --git a/web3/providers/async_base.py b/web3/providers/async_base.py index b1f6314fa1..88fbea0abc 100644 --- a/web3/providers/async_base.py +++ b/web3/providers/async_base.py @@ -112,7 +112,7 @@ def _is_batching(self) -> bool: return self._batching_context.get() is not None async def request_func( - self, async_w3: "AsyncWeb3", middleware_onion: MiddlewareOnion + self, async_w3: "AsyncWeb3[Any]", middleware_onion: MiddlewareOnion ) -> Callable[..., Coroutine[Any, Any, RPCResponse]]: middleware: Tuple[Middleware, ...] = middleware_onion.as_tuple_of_middleware() @@ -129,7 +129,7 @@ async def request_func( return self._request_func_cache[-1] async def batch_request_func( - self, async_w3: "AsyncWeb3", middleware_onion: MiddlewareOnion + self, async_w3: "AsyncWeb3[Any]", middleware_onion: MiddlewareOnion ) -> Callable[..., Coroutine[Any, Any, Union[List[RPCResponse], RPCResponse]]]: middleware: Tuple[Middleware, ...] = middleware_onion.as_tuple_of_middleware() diff --git a/web3/providers/eth_tester/defaults.py b/web3/providers/eth_tester/defaults.py index 57985a7053..d7d102ef28 100644 --- a/web3/providers/eth_tester/defaults.py +++ b/web3/providers/eth_tester/defaults.py @@ -116,7 +116,7 @@ def call_eth_tester( def without_eth_tester( - fn: Callable[[TParams], TReturn] + fn: Callable[[TParams], TReturn], ) -> Callable[["EthereumTester", TParams], TReturn]: # workaround for: https://github.com/pytoolz/cytoolz/issues/103 # @functools.wraps(fn) @@ -127,7 +127,7 @@ def inner(eth_tester: "EthereumTester", params: TParams) -> TReturn: def without_params( - fn: Callable[[TParams], TReturn] + fn: Callable[[TParams], TReturn], ) -> Callable[["EthereumTester", TParams], TReturn]: # workaround for: https://github.com/pytoolz/cytoolz/issues/103 # @functools.wraps(fn) diff --git a/web3/providers/eth_tester/main.py b/web3/providers/eth_tester/main.py index 48fdd260fb..b3510d0fd8 100644 --- a/web3/providers/eth_tester/main.py +++ b/web3/providers/eth_tester/main.py @@ -82,7 +82,7 @@ def __init__(self) -> None: self.api_endpoints = API_ENDPOINTS async def request_func( - self, async_w3: "AsyncWeb3", middleware_onion: "MiddlewareOnion" + self, async_w3: "AsyncWeb3[Any]", middleware_onion: "MiddlewareOnion" ) -> Callable[..., Coroutine[Any, Any, RPCResponse]]: # override the request_func to add the ethereum_tester_middleware diff --git a/web3/providers/eth_tester/middleware.py b/web3/providers/eth_tester/middleware.py index 6a22a083b6..56f95717de 100644 --- a/web3/providers/eth_tester/middleware.py +++ b/web3/providers/eth_tester/middleware.py @@ -376,7 +376,7 @@ def fill_default( async def async_guess_from( - async_w3: "AsyncWeb3", _: TxParams + async_w3: "AsyncWeb3[Any]", _: TxParams ) -> Optional[ChecksumAddress]: accounts = await async_w3.eth.accounts if accounts is not None and len(accounts) > 0: @@ -388,7 +388,7 @@ async def async_guess_from( async def async_fill_default( field: str, guess_func: Callable[..., Any], - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", transaction: TxParams, ) -> TxParams: # type ignored b/c TxParams keys must be string literal types diff --git a/web3/providers/persistent/persistent.py b/web3/providers/persistent/persistent.py index 7406daba58..116bd82a69 100644 --- a/web3/providers/persistent/persistent.py +++ b/web3/providers/persistent/persistent.py @@ -106,7 +106,7 @@ def __init__( # -- cached middleware request/response functions -- # async def send_func( - self, async_w3: "AsyncWeb3", middleware_onion: "MiddlewareOnion" + self, async_w3: "AsyncWeb3[Any]", middleware_onion: "MiddlewareOnion" ) -> Callable[..., Coroutine[Any, Any, RPCRequest]]: """ Cache the middleware chain for `send`. @@ -130,7 +130,7 @@ async def send_function(method: RPCEndpoint, params: Any) -> RPCRequest: return self._send_func_cache[1] async def recv_func( - self, async_w3: "AsyncWeb3", middleware_onion: "MiddlewareOnion" + self, async_w3: "AsyncWeb3[Any]", middleware_onion: "MiddlewareOnion" ) -> Any: """ Cache and compose the middleware stack for `recv`. @@ -156,7 +156,7 @@ async def recv_function(rpc_request: RPCRequest) -> RPCResponse: return self._recv_func_cache[1] async def send_batch_func( - self, async_w3: "AsyncWeb3", middleware_onion: "MiddlewareOnion" + self, async_w3: "AsyncWeb3[Any]", middleware_onion: "MiddlewareOnion" ) -> Callable[..., Coroutine[Any, Any, List[RPCRequest]]]: middleware = middleware_onion.as_tuple_of_middleware() cache_key = hash(tuple(id(mw) for mw in middleware)) @@ -179,7 +179,7 @@ async def send_func( return self._send_batch_func_cache[1] async def recv_batch_func( - self, async_w3: "AsyncWeb3", middleware_onion: "MiddlewareOnion" + self, async_w3: "AsyncWeb3[Any]", middleware_onion: "MiddlewareOnion" ) -> Callable[..., Coroutine[Any, Any, List[RPCResponse]]]: middleware = middleware_onion.as_tuple_of_middleware() cache_key = hash(tuple(id(mw) for mw in middleware)) diff --git a/web3/providers/persistent/persistent_connection.py b/web3/providers/persistent/persistent_connection.py index e5f9cf6a23..e509e9bb39 100644 --- a/web3/providers/persistent/persistent_connection.py +++ b/web3/providers/persistent/persistent_connection.py @@ -30,7 +30,7 @@ class PersistentConnection: via a `AsyncWeb3` instance instantiated with a `PersistentConnectionProvider` class. """ - def __init__(self, w3: "AsyncWeb3"): + def __init__(self, w3: "AsyncWeb3[Any]"): self._manager = w3.manager self.provider = cast("PersistentConnectionProvider", self._manager.provider) diff --git a/web3/providers/persistent/subscription_manager.py b/web3/providers/persistent/subscription_manager.py index 242b059765..baf571fc11 100644 --- a/web3/providers/persistent/subscription_manager.py +++ b/web3/providers/persistent/subscription_manager.py @@ -53,7 +53,7 @@ class SubscriptionManager: "web3.providers.persistent.subscription_manager" ) - def __init__(self, w3: "AsyncWeb3") -> None: + def __init__(self, w3: "AsyncWeb3[Any]") -> None: self._w3 = w3 self._provider = cast("PersistentConnectionProvider", w3.provider) self._subscription_container = SubscriptionContainer() diff --git a/web3/providers/persistent/utils.py b/web3/providers/persistent/utils.py index 3c625c9f52..fb2882c4a0 100644 --- a/web3/providers/persistent/utils.py +++ b/web3/providers/persistent/utils.py @@ -26,7 +26,7 @@ def persistent_connection_provider_method(message: str = None) -> Callable[..., def decorator(func: Callable[..., Any]) -> Callable[..., Any]: @functools.wraps(func) - def inner(self: "AsyncWeb3", *args: Any, **kwargs: Any) -> Any: + def inner(self: "AsyncWeb3[Any]", *args: Any, **kwargs: Any) -> Any: nonlocal message if message is None: message = ( diff --git a/web3/tools/benchmark/main.py b/web3/tools/benchmark/main.py index 5461b4e15d..50554fb45c 100644 --- a/web3/tools/benchmark/main.py +++ b/web3/tools/benchmark/main.py @@ -64,7 +64,7 @@ def build_web3_http(endpoint_uri: str) -> Web3: return _w3 -async def build_async_w3_http(endpoint_uri: str) -> AsyncWeb3: +async def build_async_w3_http(endpoint_uri: str) -> AsyncWeb3[Any]: await wait_for_aiohttp(endpoint_uri) _w3 = AsyncWeb3( AsyncHTTPProvider(endpoint_uri), diff --git a/web3/types.py b/web3/types.py index 7f980228e2..ba7c3377aa 100644 --- a/web3/types.py +++ b/web3/types.py @@ -380,7 +380,7 @@ class StateOverrideParams(TypedDict, total=False): GasPriceStrategy = Union[ - Callable[["Web3", TxParams], Wei], Callable[["AsyncWeb3", TxParams], Wei] + Callable[["Web3", TxParams], Wei], Callable[["AsyncWeb3[Any]", TxParams], Wei] ] diff --git a/web3/utils/subscriptions.py b/web3/utils/subscriptions.py index 8bd9c38b00..13849fff44 100644 --- a/web3/utils/subscriptions.py +++ b/web3/utils/subscriptions.py @@ -51,7 +51,7 @@ class EthSubscriptionContext(Generic[TSubscription, TSubscriptionResult]): def __init__( self, - async_w3: "AsyncWeb3", + async_w3: "AsyncWeb3[Any]", subscription: TSubscription, result: TSubscriptionResult, **kwargs: Any, From 5da70ada3c47a4a2e35c470e65fba50f8aa2e032 Mon Sep 17 00:00:00 2001 From: fselmo Date: Thu, 9 Oct 2025 12:45:31 -0600 Subject: [PATCH 3/8] refactor: remove unnecessary noqa: E501 uses --- web3/_utils/module_testing/module_testing_utils.py | 2 +- web3/_utils/module_testing/web3_module.py | 10 +++------- web3/providers/base.py | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/web3/_utils/module_testing/module_testing_utils.py b/web3/_utils/module_testing/module_testing_utils.py index f369d07804..191bdf6d5e 100644 --- a/web3/_utils/module_testing/module_testing_utils.py +++ b/web3/_utils/module_testing/module_testing_utils.py @@ -132,7 +132,7 @@ async def json() -> Dict[str, str]: @staticmethod def raise_for_status() -> None: - raise Exception("called raise_for_status()") # noqa: E501, E704 + raise Exception("called raise_for_status()") # noqa: E704 async def _mock_specific_request( *args: Any, **kwargs: Any diff --git a/web3/_utils/module_testing/web3_module.py b/web3/_utils/module_testing/web3_module.py index ef77368b86..a2e636532f 100644 --- a/web3/_utils/module_testing/web3_module.py +++ b/web3/_utils/module_testing/web3_module.py @@ -565,9 +565,7 @@ class AsyncWeb3ModuleTest(Web3ModuleTest): # an asynchronous test should have the exact same name. @pytest.mark.asyncio - async def test_web3_client_version( - self, async_w3: AsyncWeb3[Any] - ) -> None: # noqa: E501 + async def test_web3_client_version(self, async_w3: AsyncWeb3[Any]) -> None: client_version = await async_w3.client_version self._check_web3_client_version(client_version) @@ -643,7 +641,7 @@ async def test_batch_requests( async def test_batch_requests_initialized_as_object( self, async_w3: AsyncWeb3[Any], - async_math_contract: "AsyncContract", # noqa: E501 + async_math_contract: "AsyncContract", ) -> None: batch = async_w3.batch_requests() batch.add(async_w3.eth.get_block(1)) @@ -690,9 +688,7 @@ async def test_batch_requests_initialized_as_object( assert cast(BlockData, b4)["number"] == 4 @pytest.mark.asyncio - async def test_batch_requests_clear( - self, async_w3: AsyncWeb3[Any] - ) -> None: # noqa: E501 + async def test_batch_requests_clear(self, async_w3: AsyncWeb3[Any]) -> None: async with async_w3.batch_requests() as batch: batch.add(async_w3.eth.get_block(1)) batch.add(async_w3.eth.get_block(2)) diff --git a/web3/providers/base.py b/web3/providers/base.py index 1d8072f3a3..432f417e3c 100644 --- a/web3/providers/base.py +++ b/web3/providers/base.py @@ -194,7 +194,7 @@ def batch_request_func( # which breaks the type hinting for this particular case. accumulator_fn = initialized.wrap_make_batch_request( accumulator_fn - ) # type: ignore # noqa: E501 + ) # type: ignore self._batch_request_func_cache = (middleware, accumulator_fn) return self._batch_request_func_cache[-1] From bbe823ac4d68cdf14445b9a9f0504603fdca3feb Mon Sep 17 00:00:00 2001 From: fselmo Date: Thu, 9 Oct 2025 12:52:24 -0600 Subject: [PATCH 4/8] fix: remove `Optional` where it isn't optional --- web3/_utils/module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web3/_utils/module.py b/web3/_utils/module.py index f621586aa5..63fc151232 100644 --- a/web3/_utils/module.py +++ b/web3/_utils/module.py @@ -42,7 +42,7 @@ def _validate_init_params_and_return_if_found(module_class: Any) -> List[str]: def attach_modules( parent_module: Union["BaseWeb3", "Module"], - module_definitions: Optional[Dict[str, Any]], + module_definitions: Dict[str, Any], w3: Optional[Union["BaseWeb3", "Module"]] = None, ) -> None: for module_name, module_info in module_definitions.items(): From dcfbc54a5c3879e810e0ecf29b0dc27bd487c7a1 Mon Sep 17 00:00:00 2001 From: fselmo Date: Thu, 9 Oct 2025 12:57:12 -0600 Subject: [PATCH 5/8] fix: Use `Optional` where appropriate --- web3/main.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/web3/main.py b/web3/main.py index ee084d9bcc..0cf5a57d82 100644 --- a/web3/main.py +++ b/web3/main.py @@ -212,28 +212,36 @@ def middleware_onion(self) -> MiddlewareOnion: @staticmethod @wraps(to_bytes) def to_bytes( - primitive: Primitives = None, hexstr: HexStr = None, text: Optional[str] = None + primitive: Optional[Primitives] = None, + hexstr: Optional[HexStr] = None, + text: Optional[str] = None, ) -> bytes: return to_bytes(primitive, hexstr, text) @staticmethod @wraps(to_int) def to_int( - primitive: Primitives = None, hexstr: HexStr = None, text: Optional[str] = None + primitive: Optional[Primitives] = None, + hexstr: Optional[HexStr] = None, + text: Optional[str] = None, ) -> int: return to_int(primitive, hexstr, text) @staticmethod @wraps(to_hex) def to_hex( - primitive: Primitives = None, hexstr: HexStr = None, text: Optional[str] = None + primitive: Optional[Primitives] = None, + hexstr: Optional[HexStr] = None, + text: Optional[str] = None, ) -> HexStr: return to_hex(primitive, hexstr, text) @staticmethod @wraps(to_text) def to_text( - primitive: Primitives = None, hexstr: HexStr = None, text: Optional[str] = None + primitive: Optional[Primitives] = None, + hexstr: Optional[HexStr] = None, + text: Optional[str] = None, ) -> str: return to_text(primitive, hexstr, text) From ef9a25d066ede5b7286d5e652a45514f8aaaf197 Mon Sep 17 00:00:00 2001 From: fselmo Date: Thu, 9 Oct 2025 13:02:29 -0600 Subject: [PATCH 6/8] chore: add newsfragment for #3761 --- newsfragments/3761.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/3761.bugfix.rst diff --git a/newsfragments/3761.bugfix.rst b/newsfragments/3761.bugfix.rst new file mode 100644 index 0000000000..72d0145d8c --- /dev/null +++ b/newsfragments/3761.bugfix.rst @@ -0,0 +1 @@ +Make `AsyncWeb3` with respect to the provider it is instantiated with, fixing static type issues. From 37c26d5ab58df8a89c29334ea9f7d67dd4bf51cf Mon Sep 17 00:00:00 2001 From: Alex Harris Date: Thu, 9 Oct 2025 21:16:24 +0100 Subject: [PATCH 7/8] fix: Removed where it isn't optional --- web3/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web3/main.py b/web3/main.py index 0cf5a57d82..28a945b2c7 100644 --- a/web3/main.py +++ b/web3/main.py @@ -350,7 +350,7 @@ def solidity_keccak(cls, abi_types: List[TypeStr], values: List[Any]) -> bytes: return cls.keccak(hexstr=hex_string) def attach_modules( - self, modules: Optional[Dict[str, Union[Type[Module], Sequence[Any]]]] + self, modules: Dict[str, Union[Type[Module], Sequence[Any]]] ) -> None: """ Attach modules to the `Web3` instance. From 48e99912624edc1e51d31e7965601dba3c4450c7 Mon Sep 17 00:00:00 2001 From: kclowes Date: Thu, 16 Oct 2025 12:54:29 -0600 Subject: [PATCH 8/8] Remove unnecessary changes --- ens/async_ens.py | 8 +++++--- web3/_utils/abi.py | 4 +++- web3/_utils/batching.py | 6 +++--- web3/_utils/module_testing/web3_module.py | 10 ++++------ web3/providers/base.py | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/ens/async_ens.py b/ens/async_ens.py index 9cf003805f..51739f94a1 100644 --- a/ens/async_ens.py +++ b/ens/async_ens.py @@ -72,7 +72,9 @@ AsyncContract, AsyncContractFunction, ) - from web3.main import AsyncWeb3 # noqa: F401 + from web3.main import ( # noqa: F401 + AsyncWeb3, + ) from web3.middleware.base import ( # noqa: F401 Middleware, ) @@ -100,8 +102,8 @@ class AsyncENS(BaseENS): def __init__( self, - provider: "AsyncBaseProvider" = None, - addr: ChecksumAddress = None, + provider: Optional["AsyncBaseProvider"] = None, + addr: Optional[ChecksumAddress] = None, middleware: Optional[Sequence[Tuple["Middleware", str]]] = None, ) -> None: """ diff --git a/web3/_utils/abi.py b/web3/_utils/abi.py index 9fad0e6b42..4c835623a8 100644 --- a/web3/_utils/abi.py +++ b/web3/_utils/abi.py @@ -101,7 +101,9 @@ ) if TYPE_CHECKING: - from web3.main import AsyncWeb3 # noqa: F401 + from web3 import ( # noqa: F401 + AsyncWeb3, + ) def fallback_func_abi_exists(contract_abi: ABI) -> Sequence[ABIFallback]: diff --git a/web3/_utils/batching.py b/web3/_utils/batching.py index 462a3eb376..883b8999d1 100644 --- a/web3/_utils/batching.py +++ b/web3/_utils/batching.py @@ -167,9 +167,9 @@ def __exit__( async def async_execute(self) -> List["RPCResponse"]: self._validate_is_batching() if self._provider.has_persistent_connection: - responses = await cast( - "AsyncWeb3[Any]", self.web3 - ).manager._async_make_socket_batch_request(self._async_requests_info) + responses = await self.web3.manager._async_make_socket_batch_request( + self._async_requests_info + ) else: responses = await self.web3.manager._async_make_batch_request( self._async_requests_info diff --git a/web3/_utils/module_testing/web3_module.py b/web3/_utils/module_testing/web3_module.py index a2e636532f..7138a29b9e 100644 --- a/web3/_utils/module_testing/web3_module.py +++ b/web3/_utils/module_testing/web3_module.py @@ -717,9 +717,7 @@ async def test_batch_requests_clear(self, async_w3: AsyncWeb3[Any]) -> None: assert cast(BlockData, r3)["number"] == 6 @pytest.mark.asyncio - async def test_batch_requests_cancel( - self, async_w3: AsyncWeb3[Any] - ) -> None: # noqa: E501 + async def test_batch_requests_cancel(self, async_w3: AsyncWeb3[Any]) -> None: # as context manager async with async_w3.batch_requests() as batch: batch.add(async_w3.eth.get_block(1)) @@ -759,10 +757,10 @@ async def test_batch_requests_cancel( assert isinstance(block_num, int) @pytest.mark.asyncio - async def test_batch_requests_raises_for_common_unsupported_methods( # noqa: E501 + async def test_batch_requests_raises_for_common_unsupported_methods( self, async_w3: AsyncWeb3[Any], - async_math_contract: "AsyncContract", # noqa: E501 + async_math_contract: "AsyncContract", ) -> None: async with async_w3.batch_requests() as batch: with pytest.raises(MethodNotSupported, match="eth_sendTransaction"): @@ -785,7 +783,7 @@ async def test_batch_requests_raises_for_common_unsupported_methods( # noqa: E5 await batch.async_execute() @pytest.mark.asyncio - async def test_batch_requests_concurrently_with_regular_requests( # noqa: E501 + async def test_batch_requests_concurrently_with_regular_requests( self, async_w3: AsyncWeb3[Any] ) -> None: responses = [] diff --git a/web3/providers/base.py b/web3/providers/base.py index 432f417e3c..7a8454a637 100644 --- a/web3/providers/base.py +++ b/web3/providers/base.py @@ -192,9 +192,9 @@ def batch_request_func( # type ignore bc in order to wrap the method, we have to call # `wrap_make_batch_request` with the accumulator_fn as the argument # which breaks the type hinting for this particular case. - accumulator_fn = initialized.wrap_make_batch_request( + accumulator_fn = initialized.wrap_make_batch_request( # type: ignore accumulator_fn - ) # type: ignore + ) self._batch_request_func_cache = (middleware, accumulator_fn) return self._batch_request_func_cache[-1]