Skip to content

Commit 22fcf2b

Browse files
committed
Changes from comments on PR #2819
1 parent d44bb72 commit 22fcf2b

9 files changed

+27
-20
lines changed

web3/_utils/contracts.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,10 @@ def parse_block_identifier_int(w3: "Web3", block_identifier_int: int) -> BlockNu
439439

440440

441441
def parse_block_identifier_no_extra_call(
442-
async_w3: Union["Web3", "AsyncWeb3"], block_identifier: BlockIdentifier
442+
w3: Union["Web3", "AsyncWeb3"], block_identifier: BlockIdentifier
443443
) -> BlockIdentifier:
444444
if block_identifier is None:
445-
return async_w3.eth.default_block
445+
return w3.eth.default_block
446446
elif isinstance(block_identifier, int) and block_identifier >= 0:
447447
return block_identifier
448448
elif block_identifier in ["latest", "earliest", "pending", "safe", "finalized"]:

web3/contract/async_contract.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,7 @@ def find_functions_by_identifier(
249249
def get_function_by_identifier(
250250
cls, fns: Sequence["AsyncContractFunction"], identifier: str
251251
) -> "AsyncContractFunction":
252-
return cast(
253-
"AsyncContractFunction", get_function_by_identifier(fns, identifier)
254-
)
252+
return get_function_by_identifier(fns, identifier)
255253

256254

257255
class AsyncContractConstructor(BaseContractConstructor):

web3/contract/base_contract.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
EventData,
112112
FilterParams,
113113
FunctionIdentifier,
114+
TContractFn,
114115
TxParams,
115116
TxReceipt,
116117
)
@@ -1087,7 +1088,7 @@ def __hasattr__(self, event_name: str) -> bool:
10871088

10881089
@staticmethod
10891090
def call_function(
1090-
fn: Union["ContractFunction", "AsyncContractFunction"],
1091+
fn: TContractFn,
10911092
*args: Any,
10921093
transaction: Optional[TxParams] = None,
10931094
block_identifier: BlockIdentifier = "latest",

web3/contract/contract.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def find_functions_by_identifier(
371371
def get_function_by_identifier(
372372
cls, fns: Sequence["ContractFunction"], identifier: str
373373
) -> "ContractFunction":
374-
return cast("ContractFunction", get_function_by_identifier(fns, identifier))
374+
return get_function_by_identifier(fns, identifier)
375375

376376

377377
class ContractConstructor(BaseContractConstructor):

web3/contract/utils.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
BlockIdentifier,
5151
CallOverride,
5252
FunctionIdentifier,
53+
TContractFn,
5354
TxParams,
5455
)
5556

@@ -240,8 +241,8 @@ def find_functions_by_identifier(
240241
w3: Union["Web3", "AsyncWeb3"],
241242
address: ChecksumAddress,
242243
callable_check: Callable[..., Any],
243-
function_type: Type[Union["ContractFunction", "AsyncContractFunction"]],
244-
) -> List[Union["ContractFunction", "AsyncContractFunction"]]:
244+
function_type: Type[TContractFn],
245+
) -> List[TContractFn]:
245246
fns_abi = filter_by_type("function", contract_abi)
246247
return [
247248
function_type.factory(
@@ -258,8 +259,8 @@ def find_functions_by_identifier(
258259

259260

260261
def get_function_by_identifier(
261-
fns: Sequence[Union["ContractFunction", "AsyncContractFunction"]], identifier: str
262-
) -> Union["ContractFunction", "AsyncContractFunction"]:
262+
fns: Sequence[TContractFn], identifier: str
263+
) -> TContractFn:
263264
if len(fns) > 1:
264265
raise ValueError(
265266
f"Found multiple functions with matching {identifier}. " f"Found: {fns!r}"

web3/eth/async_eth.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -557,15 +557,15 @@ async def uninstall_filter(self, filter_id: HexStr) -> bool:
557557

558558
@overload
559559
def contract(self, address: None = None, **kwargs: Any) -> Type[AsyncContract]:
560-
... # noqa: E704,E501
560+
...
561561

562-
@overload # noqa: F811
562+
@overload
563563
def contract(
564564
self, address: Union[Address, ChecksumAddress, ENS], **kwargs: Any
565565
) -> AsyncContract:
566-
... # noqa: E704,E501
566+
...
567567

568-
def contract( # noqa: F811
568+
def contract(
569569
self,
570570
address: Optional[Union[Address, ChecksumAddress, ENS]] = None,
571571
**kwargs: Any,

web3/eth/eth.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -643,15 +643,15 @@ def sign_munger(
643643

644644
@overload
645645
def contract(self, address: None = None, **kwargs: Any) -> Type[Contract]:
646-
... # noqa: E704,E501
646+
...
647647

648-
@overload # noqa: F811
648+
@overload
649649
def contract(
650650
self, address: Union[Address, ChecksumAddress, ENS], **kwargs: Any
651651
) -> Contract:
652-
... # noqa: E704,E501
652+
...
653653

654-
def contract( # noqa: F811
654+
def contract(
655655
self,
656656
address: Optional[Union[Address, ChecksumAddress, ENS]] = None,
657657
**kwargs: Any,

web3/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def keccak(
282282

283283
@classmethod
284284
def normalize_values(
285-
cls, w3: "BaseWeb3", abi_types: List[TypeStr], values: List[Any]
285+
cls, _w3: "BaseWeb3", abi_types: List[TypeStr], values: List[Any]
286286
) -> List[Any]:
287287
return map_abi_data(zip(abi_types, values))
288288

web3/types.py

+7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
)
3838

3939
if TYPE_CHECKING:
40+
from web3.contract.async_contract import AsyncContractFunction # noqa: F401
41+
from web3.contract.contract import ContractFunction # noqa: F401
4042
from web3.main import ( # noqa: F401
4143
AsyncWeb3,
4244
Web3,
@@ -434,3 +436,8 @@ class GethWallet(TypedDict):
434436
accounts: Sequence[Dict[str, str]]
435437
status: str
436438
url: str
439+
440+
441+
# Contract types
442+
443+
TContractFn = TypeVar("TContractFn", "ContractFunction", "AsyncContractFunction")

0 commit comments

Comments
 (0)