Skip to content

Commit 97c4f99

Browse files
committed
remove unused type:ignores, bump requests to >=2.23 where it first supports py38, add types-requests to install_requires, clear mypy errors
1 parent eecd338 commit 97c4f99

24 files changed

+124
-75
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ repos:
4747
hooks:
4848
- id: mypy-local
4949
name: run mypy with all dev dependencies present
50-
# exclude: 'tests/|conftest.py'
5150
entry: python -m mypy -p web3
5251
language: system
5352
always_run: true

ens/async_ens.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import (
55
TYPE_CHECKING,
66
Any,
7+
Coroutine,
78
Optional,
89
Sequence,
910
Tuple,
@@ -469,9 +470,13 @@ async def _set_resolver(
469470
resolver_addr = await self.address("resolver.eth")
470471
namehash = raw_name_to_hash(name)
471472
if await self.ens.caller.resolver(namehash) != resolver_addr:
472-
await self.ens.functions.setResolver(namehash, resolver_addr).transact(
473-
transact
473+
coro = cast(
474+
Coroutine[Any, Any, HexBytes],
475+
self.ens.functions.setResolver(namehash, resolver_addr).transact(
476+
transact
477+
),
474478
)
479+
await coro
475480
return cast("AsyncContract", self._resolver_contract(address=resolver_addr))
476481

477482
async def _resolve(
@@ -553,11 +558,15 @@ async def _claim_ownership(
553558
transact = deepcopy(transact)
554559
transact["from"] = old_owner or owner
555560
for label in reversed(unowned):
556-
await self.ens.functions.setSubnodeOwner(
557-
raw_name_to_hash(owned),
558-
label_to_hash(label),
559-
owner,
560-
).transact(transact)
561+
coro = cast(
562+
Coroutine[Any, Any, HexBytes],
563+
self.ens.functions.setSubnodeOwner(
564+
raw_name_to_hash(owned),
565+
label_to_hash(label),
566+
owner,
567+
).transact(transact),
568+
)
569+
await coro
561570
owned = f"{label}.{owned}"
562571

563572
async def _setup_reverse(

ens/exceptions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class AddressMismatch(ENSException):
2929
"""
3030

3131

32-
# type ignored because subclassing IDNAError which has type Any
33-
class InvalidName(idna.IDNAError, ENSException): # type: ignore[misc]
32+
class InvalidName(idna.IDNAError, ENSException):
3433
"""
3534
Raised if the provided name does not meet the normalization
3635
standards specified in `ENSIP-15

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ check_untyped_defs = true
2121
disallow_any_generics = true
2222
disallow_incomplete_defs = true
2323
disallow_subclassing_any = true
24-
disallow_untyped_calls = true
24+
disallow_untyped_calls = false
2525
disallow_untyped_decorators = false
2626
disallow_untyped_defs = true
2727
ignore_missing_imports = true
@@ -32,7 +32,6 @@ warn_return_any = false
3232
warn_unused_configs = true
3333
warn_unused_ignores = true
3434

35-
3635
[tool.pydocstyle]
3736
# All error codes found here:
3837
# http://www.pydocstyle.org/en/3.0.0/error_codes.html

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@
7070
"hexbytes>=1.2.0",
7171
"pydantic>=2.4.0",
7272
"pywin32>=223;platform_system=='Windows'",
73-
"requests>=2.16.0",
73+
"requests>=2.23.0",
7474
"typing-extensions>=4.0.1",
75+
"types-requests>=2.0.0",
7576
"websockets>=10.0.0",
7677
"pyunormalize>=15.0.0",
7778
],

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ basepython =
5454

5555
[testenv:py{38,39,310,311,312}-lint]
5656
deps=pre-commit
57+
extras=dev
5758
commands=
5859
pre-commit install
5960
pre-commit run --all-files --show-diff-on-failure

web3/_utils/abi.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ def filter_by_argument_name(
147147
return abis_with_matching_args
148148

149149

150-
# type ignored because subclassing encoding.AddressEncoder which has type Any
151-
class AddressEncoder(encoding.AddressEncoder): # type: ignore[misc]
150+
class AddressEncoder(encoding.AddressEncoder):
152151
@classmethod
153152
def validate_value(cls, value: Any) -> None:
154153
if is_ens_name(value):
@@ -157,8 +156,7 @@ def validate_value(cls, value: Any) -> None:
157156
super().validate_value(value)
158157

159158

160-
# type ignored because subclassing encoding.BytesEncoder which has type Any
161-
class AcceptsHexStrEncoder(encoding.BaseEncoder): # type: ignore[misc]
159+
class AcceptsHexStrEncoder(encoding.BaseEncoder):
162160
subencoder_cls: Type[encoding.BaseEncoder] = None
163161
is_strict: bool = None
164162
is_big_endian: bool = False
@@ -270,10 +268,16 @@ def from_type_str(
270268
) -> "ExactLengthBytesEncoder":
271269
subencoder_cls = cls.get_subencoder_class()
272270
subencoder = subencoder_cls.from_type_str(abi_type.to_type_str(), registry)
273-
return cls(
274-
subencoder,
275-
value_bit_size=abi_type.sub * 8,
276-
data_byte_size=abi_type.sub,
271+
return cast(
272+
ExactLengthBytesEncoder,
273+
# type ignored b/c mypy thinks the __call__ is from BaseEncoder, but it's
274+
# from ExactLengthBytesEncoder, which does have value_bit_size and
275+
# data_byte_size attributes
276+
cls( # type: ignore[call-arg]
277+
subencoder,
278+
value_bit_size=abi_type.sub * 8,
279+
data_byte_size=abi_type.sub,
280+
),
277281
)
278282

279283

@@ -287,8 +291,7 @@ class StrictByteStringEncoder(AcceptsHexStrEncoder):
287291
is_strict = True
288292

289293

290-
# type ignored because subclassing encoding.TextStringEncoder which has type Any
291-
class TextStringEncoder(encoding.TextStringEncoder): # type: ignore[misc]
294+
class TextStringEncoder(encoding.TextStringEncoder):
292295
@classmethod
293296
def validate_value(cls, value: Any) -> None:
294297
if is_bytes(value):

web3/_utils/compat/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
NotRequired, # py311
1313
Self, # py311
1414
Unpack, # py311
15+
TypeAlias, # py310
1516
)

web3/_utils/encoding.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ def to_4byte_hex(hex_or_str_or_bytes: Union[HexStr, str, bytes, int]) -> HexStr:
255255
return pad_hex(hex_str, size_of_4bytes)
256256

257257

258-
# type ignored because subclassing BaseArrayEncoder which has type Any
259-
class DynamicArrayPackedEncoder(BaseArrayEncoder): # type: ignore[misc]
258+
class DynamicArrayPackedEncoder(BaseArrayEncoder):
260259
is_dynamic = True
261260

262261
def encode(self, value: Sequence[Any]) -> bytes:

web3/_utils/events.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def construct_event_topic_set(
134134
for key, value in arguments.items() # type: ignore
135135
}
136136

137-
event_topic = encode_hex(event_abi_to_log_topic(event_abi))
137+
event_topic = encode_hex(event_abi_to_log_topic(cast(Dict[str, Any], event_abi)))
138138
indexed_args = get_indexed_event_inputs(event_abi)
139139
zipped_abi_and_args = [
140140
(arg, normalized_args.get(arg["name"], [None])) for arg in indexed_args
@@ -459,8 +459,8 @@ async def deploy(self, async_w3: "AsyncWeb3") -> "AsyncLogFilter":
459459
if not isinstance(async_w3, web3.AsyncWeb3):
460460
raise Web3ValueError(f"Invalid web3 argument: got: {async_w3!r}")
461461

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

466466
log_filter = await async_w3.eth.filter(self.filter_params)
@@ -475,7 +475,7 @@ async def deploy(self, async_w3: "AsyncWeb3") -> "AsyncLogFilter":
475475

476476
def initialize_event_topics(event_abi: ABIEvent) -> Union[bytes, List[Any]]:
477477
if event_abi["anonymous"] is False:
478-
return event_abi_to_log_topic(event_abi)
478+
return event_abi_to_log_topic(cast(Dict[str, Any], event_abi))
479479
else:
480480
return list()
481481

0 commit comments

Comments
 (0)