Skip to content

Commit

Permalink
Bumps MyPy version
Browse files Browse the repository at this point in the history
Fixes / ignores any warnings that appeared as a result
  • Loading branch information
konichuvak committed Jun 22, 2023
1 parent 7d60ef2 commit 7d34064
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -13,7 +13,7 @@
"black>=22.1.0",
"flake8==3.8.3",
"isort>=5.11.0",
"mypy==0.910",
"mypy>=1.0.0",
"types-setuptools>=57.4.4",
"types-requests>=2.26.1",
"types-protobuf==3.19.13",
Expand Down
10 changes: 6 additions & 4 deletions web3/_utils/contract_sources/compile_contracts.py
Expand Up @@ -48,6 +48,8 @@
import re
from typing import (
Any,
Dict,
List,
)

import solcx
Expand Down Expand Up @@ -79,7 +81,7 @@
files_to_compile = [user_filename] if user_filename else all_dot_sol_files


def _compile_dot_sol_files(dot_sol_filename: str) -> dict[str, Any]:
def _compile_dot_sol_files(dot_sol_filename: str) -> Dict[str, Any]:
compiled = solcx.compile_files(
[f"./{dot_sol_filename}"],
output_values=["abi", "bin", "bin-runtime"],
Expand All @@ -88,10 +90,10 @@ def _compile_dot_sol_files(dot_sol_filename: str) -> dict[str, Any]:


def _get_compiled_contract_data(
sol_file_output: dict[str, dict[str, str]],
sol_file_output: Dict[str, Dict[str, str]],
dot_sol_filename: str,
contract_name: str = None,
) -> dict[str, str]:
) -> Dict[str, str]:
if not contract_name:
contract_name = dot_sol_filename.replace(".sol", "")

Expand All @@ -111,7 +113,7 @@ def _get_compiled_contract_data(
contracts_in_file = {}


def compile_files(file_list: list[str]) -> None:
def compile_files(file_list: List[str]) -> None:
for filename in file_list:
with open(os.path.join(os.getcwd(), filename), "r") as f:
dot_sol_file = f.readlines()
Expand Down
14 changes: 7 additions & 7 deletions web3/_utils/events.py
Expand Up @@ -140,7 +140,7 @@ def construct_event_topic_set(
for arg, arg_options in zipped_abi_and_args
]

topics = list(normalize_topic_list([event_topic] + encoded_args)) # type: ignore
topics = list(normalize_topic_list([event_topic] + encoded_args))
return topics


Expand Down Expand Up @@ -394,12 +394,12 @@ def address(self, value: ChecksumAddress) -> None:
def ordered_args(self) -> Tuple[Any, ...]:
return tuple(map(self.args.__getitem__, self._ordered_arg_names))

@property # type: ignore
@property
@to_tuple
def indexed_args(self) -> Tuple[Any, ...]:
return tuple(filter(is_indexed, self.ordered_args))

@property # type: ignore
@property
@to_tuple
def data_args(self) -> Tuple[Any, ...]:
return tuple(filter(is_not_indexed, self.ordered_args))
Expand Down Expand Up @@ -432,8 +432,8 @@ def deploy(self, w3: "Web3") -> "LogFilter":
if not isinstance(w3, web3.Web3):
raise ValueError(f"Invalid web3 argument: got: {w3!r}")

for arg in AttributeDict.values(self.args):
arg._immutable = True
for arg in AttributeDict.values(self.args): # type: ignore[arg-type]
arg._immutable = True # type: ignore[attr-defined]
self._immutable = True

log_filter = cast("LogFilter", w3.eth.filter(self.filter_params))
Expand All @@ -450,8 +450,8 @@ async def deploy(self, async_w3: "AsyncWeb3") -> "AsyncLogFilter":
if not isinstance(async_w3, web3.AsyncWeb3):
raise ValueError(f"Invalid web3 argument: got: {async_w3!r}")

for arg in AttributeDict.values(self.args):
arg._immutable = True
for arg in AttributeDict.values(self.args): # type: ignore[arg-type]
arg._immutable = True # type: ignore[attr-defined]
self._immutable = True

log_filter = await async_w3.eth.filter(self.filter_params)
Expand Down
2 changes: 1 addition & 1 deletion web3/_utils/module_testing/web3_module.py
Expand Up @@ -229,7 +229,7 @@ def test_solidity_keccak(
expected: HexBytes,
) -> None:
if isinstance(expected, type) and issubclass(expected, Exception):
with pytest.raises(expected): # type: ignore
with pytest.raises(expected):
w3.solidity_keccak(types, values)
return

Expand Down
13 changes: 7 additions & 6 deletions web3/contract/base_contract.py
Expand Up @@ -454,8 +454,9 @@ def _get_call_txparams(self, transaction: Optional[TxParams] = None) -> TxParams
call_transaction.setdefault("to", self.address)
if self.w3.eth.default_account is not empty:
# type ignored b/c check prevents an empty default_account
call_transaction.setdefault(
"from", self.w3.eth.default_account # type: ignore
call_transaction.setdefault( # type: ignore
"from",
self.w3.eth.default_account, # type: ignore
)

if "to" not in call_transaction:
Expand Down Expand Up @@ -485,7 +486,7 @@ def _transact(self, transaction: Optional[TxParams] = None) -> TxParams:
transact_transaction.setdefault("to", self.address)
if self.w3.eth.default_account is not empty:
# type ignored b/c check prevents an empty default_account
transact_transaction.setdefault(
transact_transaction.setdefault( # type: ignore
"from", self.w3.eth.default_account # type: ignore
)

Expand Down Expand Up @@ -516,7 +517,7 @@ def _estimate_gas(self, transaction: Optional[TxParams] = None) -> TxParams:
estimate_gas_transaction.setdefault("to", self.address)
if self.w3.eth.default_account is not empty:
# type ignored b/c check prevents an empty default_account
estimate_gas_transaction.setdefault(
estimate_gas_transaction.setdefault( # type: ignore
"from", self.w3.eth.default_account # type: ignore
)

Expand Down Expand Up @@ -1041,7 +1042,7 @@ def _estimate_gas(self, transaction: Optional[TxParams] = None) -> TxParams:

if self.w3.eth.default_account is not empty:
# type ignored b/c check prevents an empty default_account
estimate_gas_transaction.setdefault(
estimate_gas_transaction.setdefault( # type: ignore
"from", self.w3.eth.default_account # type: ignore
)

Expand All @@ -1060,7 +1061,7 @@ def _get_transaction(self, transaction: Optional[TxParams] = None) -> TxParams:

if self.w3.eth.default_account is not empty:
# type ignored b/c check prevents an empty default_account
transact_transaction.setdefault(
transact_transaction.setdefault( # type: ignore
"from", self.w3.eth.default_account # type: ignore
)

Expand Down
2 changes: 1 addition & 1 deletion web3/main.py
Expand Up @@ -335,7 +335,7 @@ def pm(self) -> "PM":
if hasattr(self, "_pm"):
# ignored b/c property is dynamically set
# via enable_unstable_package_management_api
return self._pm # type: ignore
return self._pm
else:
raise AttributeError(
"The Package Management feature is disabled by default until "
Expand Down

0 comments on commit 7d34064

Please sign in to comment.