diff --git a/newsfragments/3207.internal.rst b/newsfragments/3207.internal.rst new file mode 100644 index 0000000000..5d065a3603 --- /dev/null +++ b/newsfragments/3207.internal.rst @@ -0,0 +1 @@ +Formatting updates for ``black==24.1.0``. \ No newline at end of file diff --git a/tests/core/eth-module/test_transactions.py b/tests/core/eth-module/test_transactions.py index 7484fd29d2..6321207304 100644 --- a/tests/core/eth-module/test_transactions.py +++ b/tests/core/eth-module/test_transactions.py @@ -187,9 +187,11 @@ def test_unmined_transaction_wait_for_receipt(w3, request_mocker): with request_mocker( w3, mock_results={ - RPC.eth_getTransactionReceipt: lambda method, params: None - if next(receipt_counters[params[0]]) < 5 - else unmocked_make_request(method, params)["result"] + RPC.eth_getTransactionReceipt: lambda method, params: ( + None + if next(receipt_counters[params[0]]) < 5 + else unmocked_make_request(method, params)["result"] + ) }, ): with pytest.raises(TransactionNotFound): diff --git a/tests/core/utilities/test_abi.py b/tests/core/utilities/test_abi.py index 35f7cc47ee..09f944196c 100644 --- a/tests/core/utilities/test_abi.py +++ b/tests/core/utilities/test_abi.py @@ -296,9 +296,9 @@ def test_abi_data_tree(types, data, expected): ["bool[2]", "int256"], [[True, False], 9876543210], [ - lambda typ, dat: (typ, "Tru-dat") - if typ == "bool" and dat - else (typ, dat), + lambda typ, dat: ( + (typ, "Tru-dat") if typ == "bool" and dat else (typ, dat) + ), lambda typ, dat: (typ, hex(dat)) if typ == "int256" else (typ, dat), ], [["Tru-dat", False], "0x24cb016ea"], diff --git a/web3/_utils/contract_sources/compile_contracts.py b/web3/_utils/contract_sources/compile_contracts.py index 8241d5fa64..7347eb8f71 100644 --- a/web3/_utils/contract_sources/compile_contracts.py +++ b/web3/_utils/contract_sources/compile_contracts.py @@ -42,7 +42,6 @@ reformatted ... """ - import argparse import os import re diff --git a/web3/_utils/events.py b/web3/_utils/events.py index 1411f7bdba..543d33bf5b 100644 --- a/web3/_utils/events.py +++ b/web3/_utils/events.py @@ -132,9 +132,11 @@ def construct_event_topic_set( ] encoded_args = [ [ - None - if option is None - else encode_hex(abi_codec.encode([arg["type"]], [option])) + ( + None + if option is None + else encode_hex(abi_codec.encode([arg["type"]], [option])) + ) for option in arg_options ] for arg, arg_options in zipped_abi_and_args @@ -174,9 +176,11 @@ def construct_event_data_set( ] encoded_args = [ [ - None - if option is None - else encode_hex(abi_codec.encode([arg["type"]], [option])) + ( + None + if option is None + else encode_hex(abi_codec.encode([arg["type"]], [option])) + ) for option in arg_options ] for arg, arg_options in zipped_abi_and_args diff --git a/web3/_utils/fee_utils.py b/web3/_utils/fee_utils.py index a5755bd77a..df2a06644c 100644 --- a/web3/_utils/fee_utils.py +++ b/web3/_utils/fee_utils.py @@ -33,9 +33,11 @@ def _fee_history_priority_fee_estimate(fee_history: FeeHistory) -> Wei: return ( # keep estimated priority fee within a max / min range PRIORITY_FEE_MAX if priority_fee_average_for_percentile > PRIORITY_FEE_MAX - else PRIORITY_FEE_MIN - if priority_fee_average_for_percentile < PRIORITY_FEE_MIN - else priority_fee_average_for_percentile + else ( + PRIORITY_FEE_MIN + if priority_fee_average_for_percentile < PRIORITY_FEE_MIN + else priority_fee_average_for_percentile + ) ) diff --git a/web3/_utils/module_testing/utils.py b/web3/_utils/module_testing/utils.py index b2e30ea274..bda7e2a57b 100644 --- a/web3/_utils/module_testing/utils.py +++ b/web3/_utils/module_testing/utils.py @@ -60,9 +60,9 @@ def __init__( self.w3 = w3 self.mock_results = mock_results or {} self.mock_errors = mock_errors or {} - self._make_request: Union[ - "AsyncMakeRequestFn", "MakeRequestFn" - ] = w3.provider.make_request + self._make_request: Union["AsyncMakeRequestFn", "MakeRequestFn"] = ( + w3.provider.make_request + ) def __enter__(self) -> "Self": setattr(self.w3.provider, "make_request", self._mock_request_handler) diff --git a/web3/_utils/request.py b/web3/_utils/request.py index 716e968a6c..8a01be5594 100644 --- a/web3/_utils/request.py +++ b/web3/_utils/request.py @@ -157,9 +157,11 @@ async def async_cache_and_return_session( warning = ( "Async session was closed" if session_is_closed - else "Loop was closed for async session" - if session_loop_is_closed - else None + else ( + "Loop was closed for async session" + if session_loop_is_closed + else None + ) ) if warning: logger.debug( diff --git a/web3/_utils/threads.py b/web3/_utils/threads.py index 991c7cf254..4ce80d7e17 100644 --- a/web3/_utils/threads.py +++ b/web3/_utils/threads.py @@ -1,6 +1,7 @@ """ A minimal implementation of the various gevent APIs used within this codebase. """ + import asyncio import threading import time diff --git a/web3/eth/async_eth.py b/web3/eth/async_eth.py index 62b4838e03..1da4442bb7 100644 --- a/web3/eth/async_eth.py +++ b/web3/eth/async_eth.py @@ -104,9 +104,9 @@ class AsyncEth(BaseEth): is_async = True - _default_contract_factory: Type[ - Union[AsyncContract, AsyncContractCaller] - ] = AsyncContract + _default_contract_factory: Type[Union[AsyncContract, AsyncContractCaller]] = ( + AsyncContract + ) # eth_accounts @@ -382,15 +382,15 @@ async def get_raw_transaction_by_block( # eth_getBlockTransactionCountByHash # eth_getBlockTransactionCountByNumber - get_block_transaction_count: Method[ - Callable[[BlockIdentifier], Awaitable[int]] - ] = Method( - method_choice_depends_on_args=select_method_for_block_identifier( - if_predefined=RPC.eth_getBlockTransactionCountByNumber, - if_hash=RPC.eth_getBlockTransactionCountByHash, - if_number=RPC.eth_getBlockTransactionCountByNumber, - ), - mungers=[default_root_munger], + get_block_transaction_count: Method[Callable[[BlockIdentifier], Awaitable[int]]] = ( + Method( + method_choice_depends_on_args=select_method_for_block_identifier( + if_predefined=RPC.eth_getBlockTransactionCountByNumber, + if_hash=RPC.eth_getBlockTransactionCountByHash, + if_number=RPC.eth_getBlockTransactionCountByNumber, + ), + mungers=[default_root_munger], + ) ) # eth_sendTransaction @@ -417,15 +417,15 @@ async def send_raw_transaction(self, transaction: Union[HexStr, bytes]) -> HexBy # eth_getBlockByHash # eth_getBlockByNumber - _get_block: Method[ - Callable[[BlockIdentifier, bool], Awaitable[BlockData]] - ] = Method( - method_choice_depends_on_args=select_method_for_block_identifier( - if_predefined=RPC.eth_getBlockByNumber, - if_hash=RPC.eth_getBlockByHash, - if_number=RPC.eth_getBlockByNumber, - ), - mungers=[BaseEth.get_block_munger], + _get_block: Method[Callable[[BlockIdentifier, bool], Awaitable[BlockData]]] = ( + Method( + method_choice_depends_on_args=select_method_for_block_identifier( + if_predefined=RPC.eth_getBlockByNumber, + if_hash=RPC.eth_getBlockByHash, + if_number=RPC.eth_getBlockByNumber, + ), + mungers=[BaseEth.get_block_munger], + ) ) async def get_block( @@ -653,9 +653,9 @@ async def get_uncle_count(self, block_identifier: BlockIdentifier) -> int: # eth_getFilterChanges, eth_getFilterLogs, eth_uninstallFilter - _get_filter_changes: Method[ - Callable[[HexStr], Awaitable[List[LogReceipt]]] - ] = Method(RPC.eth_getFilterChanges, mungers=[default_root_munger]) + _get_filter_changes: Method[Callable[[HexStr], Awaitable[List[LogReceipt]]]] = ( + Method(RPC.eth_getFilterChanges, mungers=[default_root_munger]) + ) async def get_filter_changes(self, filter_id: HexStr) -> List[LogReceipt]: return await self._get_filter_changes(filter_id) @@ -733,14 +733,12 @@ async def unsubscribe(self, subscription_id: HexStr) -> bool: # -- contract methods -- # @overload - def contract(self, address: None = None, **kwargs: Any) -> Type[AsyncContract]: - ... + def contract(self, address: None = None, **kwargs: Any) -> Type[AsyncContract]: ... @overload def contract( self, address: Union[Address, ChecksumAddress, ENS], **kwargs: Any - ) -> AsyncContract: - ... + ) -> AsyncContract: ... def contract( self, diff --git a/web3/eth/eth.py b/web3/eth/eth.py index 8d7bd47c92..564a012713 100644 --- a/web3/eth/eth.py +++ b/web3/eth/eth.py @@ -301,9 +301,9 @@ def create_access_list( # eth_estimateGas - _estimate_gas: Method[ - Callable[[TxParams, Optional[BlockIdentifier]], int] - ] = Method(RPC.eth_estimateGas, mungers=[BaseEth.estimate_gas_munger]) + _estimate_gas: Method[Callable[[TxParams, Optional[BlockIdentifier]], int]] = ( + Method(RPC.eth_estimateGas, mungers=[BaseEth.estimate_gas_munger]) + ) def estimate_gas( self, transaction: TxParams, block_identifier: Optional[BlockIdentifier] = None @@ -615,15 +615,15 @@ def modify_transaction( # eth_newFilter, eth_newBlockFilter, eth_newPendingTransactionFilter - filter: Method[ - Callable[[Optional[Union[str, FilterParams, HexStr]]], Filter] - ] = Method( - method_choice_depends_on_args=select_filter_method( - if_new_block_filter=RPC.eth_newBlockFilter, - if_new_pending_transaction_filter=RPC.eth_newPendingTransactionFilter, - if_new_filter=RPC.eth_newFilter, - ), - mungers=[BaseEth.filter_munger], + filter: Method[Callable[[Optional[Union[str, FilterParams, HexStr]]], Filter]] = ( + Method( + method_choice_depends_on_args=select_filter_method( + if_new_block_filter=RPC.eth_newBlockFilter, + if_new_pending_transaction_filter=RPC.eth_newPendingTransactionFilter, + if_new_filter=RPC.eth_newFilter, + ), + mungers=[BaseEth.filter_munger], + ) ) # eth_getFilterChanges, eth_getFilterLogs, eth_uninstallFilter @@ -661,14 +661,12 @@ def modify_transaction( ) @overload - def contract(self, address: None = None, **kwargs: Any) -> Type[Contract]: - ... + def contract(self, address: None = None, **kwargs: Any) -> Type[Contract]: ... @overload def contract( self, address: Union[Address, ChecksumAddress, ENS], **kwargs: Any - ) -> Contract: - ... + ) -> Contract: ... def contract( self, diff --git a/web3/method.py b/web3/method.py index e6f350bec2..e4f8a7849d 100644 --- a/web3/method.py +++ b/web3/method.py @@ -66,9 +66,7 @@ def _set_mungers( return ( mungers if mungers - else [default_munger] - if is_property - else [default_root_munger] + else [default_munger] if is_property else [default_root_munger] ) @@ -177,9 +175,7 @@ def input_munger(self, module: "Module", args: Any, kwargs: Any) -> List[Any]: lambda args, munger: munger(module, *args, **kwargs), self.mungers, args ) - def process_params( - self, module: "Module", *args: Any, **kwargs: Any - ) -> Tuple[ + def process_params(self, module: "Module", *args: Any, **kwargs: Any) -> Tuple[ Tuple[Union[RPCEndpoint, Callable[..., RPCEndpoint]], Tuple[Any, ...]], Tuple[ Union[TReturn, Dict[str, Callable[..., Any]]], diff --git a/web3/utils/__init__.py b/web3/utils/__init__.py index 81a4decb4c..13c24de6a0 100644 --- a/web3/utils/__init__.py +++ b/web3/utils/__init__.py @@ -2,6 +2,7 @@ NOTE: This is a public utility module. Any changes to these utility methods would classify as breaking changes. """ + from .abi import ( # NOQA get_abi_input_names, get_abi_output_names,