Skip to content

Commit 1b5d7ae

Browse files
committed
Some cleanup. Leave async typing decisions to upcoming PR.
- No need for the ``Net`` module to be the only one to have to `cast` values because the `net` property on `Web3` is a `Union[Net, AsyncNet]`. Instead, set it like the others and make one decision for all at the same time in an upcoming PR.
1 parent 00daa0f commit 1b5d7ae

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

tests/core/providers/test_async_http_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def test_web3_with_async_http_provider_has_default_middlewares_and_modules() ->
5151
# assert default modules
5252

5353
assert isinstance(async_w3.eth, AsyncEth)
54-
assert isinstance(async_w3.geth, Geth)
5554
assert isinstance(async_w3.net, AsyncNet)
55+
assert isinstance(async_w3.geth, Geth)
5656
assert isinstance(async_w3.geth.admin, AsyncGethAdmin)
5757
assert isinstance(async_w3.geth.personal, AsyncGethPersonal)
5858
assert isinstance(async_w3.geth.txpool, AsyncGethTxPool)

web3/_utils/module_testing/net_module.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22
from typing import (
33
TYPE_CHECKING,
4-
cast,
54
)
65

76
from eth_utils import (
@@ -16,7 +15,7 @@
1615

1716
class NetModuleTest:
1817
def test_net_version(self, w3: "Web3") -> None:
19-
version = cast(str, w3.net.version)
18+
version = w3.net.version
2019

2120
assert is_string(version)
2221
assert version.isdigit()

web3/_utils/normalizers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def abi_ens_resolver(
218218
)
219219

220220
_ens = cast(ENS, w3.ens)
221-
net_version = int(cast(str, w3.net.version)) if hasattr(w3, "net") else None
221+
net_version = int(w3.net.version) if hasattr(w3, "net") else None
222222
if _ens is None:
223223
raise InvalidAddress(
224224
f"Could not look up name {val!r} because ENS is" " set to None"

web3/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def to_checksum_address(value: Union[AnyAddress, str, bytes]) -> ChecksumAddress
237237
# mypy Types
238238
eth: Eth
239239
geth: Geth
240-
net: Union[Net, AsyncNet]
240+
net: Net
241241

242242
def __init__(
243243
self,

web3/manager.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@ def __init__(
111111
self.provider = provider
112112

113113
if middlewares is None:
114-
if self.provider.is_async:
115-
middlewares = self.async_default_middlewares(w3)
116-
else:
117-
middlewares = self.default_middlewares(w3)
114+
middlewares = (
115+
self.async_default_middlewares(w3)
116+
if self.provider.is_async
117+
else self.default_middlewares(w3)
118+
)
118119

119120
self.middleware_onion: MiddlewareOnion = NamedElementOnion(middlewares)
120121

0 commit comments

Comments
 (0)