Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/3207.internal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Formatting updates for ``black==24.1.0``.
8 changes: 5 additions & 3 deletions tests/core/eth-module/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions tests/core/utilities/test_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
1 change: 0 additions & 1 deletion web3/_utils/contract_sources/compile_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
reformatted ...
"""


import argparse
import os
import re
Expand Down
16 changes: 10 additions & 6 deletions web3/_utils/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions web3/_utils/fee_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)


Expand Down
6 changes: 3 additions & 3 deletions web3/_utils/module_testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions web3/_utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions web3/_utils/threads.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
A minimal implementation of the various gevent APIs used within this codebase.
"""

import asyncio
import threading
import time
Expand Down
54 changes: 26 additions & 28 deletions web3/eth/async_eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
30 changes: 14 additions & 16 deletions web3/eth/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions web3/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)


Expand Down Expand Up @@ -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]]],
Expand Down
1 change: 1 addition & 0 deletions web3/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down