Skip to content

Commit 5a6d2e2

Browse files
committed
address comments on PR #2547
1 parent c5f2b8c commit 5a6d2e2

File tree

4 files changed

+13
-22
lines changed

4 files changed

+13
-22
lines changed

tests/ens/test_get_text.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@
1010
)
1111
from web3 import Web3
1212

13-
SET_TEXT_RESOLVER_NOT_FOUND_CASES = (
14-
("avatar", "tester.jpeg"),
15-
("email", "user@example.com"),
16-
("url", "http://example.com"),
17-
("description", "a test"),
18-
("notice", "this contract is a test contract"),
19-
)
2013
GET_TEXT_TEST_CASES = (
2114
("avatar", "tester.jpeg"),
2215
("email", "user@example.com"),
@@ -26,7 +19,7 @@
2619
)
2720

2821

29-
@pytest.mark.parametrize("key,expected", SET_TEXT_RESOLVER_NOT_FOUND_CASES)
22+
@pytest.mark.parametrize("key,expected", GET_TEXT_TEST_CASES)
3023
def test_set_text_resolver_not_found(ens, key, expected):
3124
with pytest.raises(ResolverNotFound):
3225
ens.set_text("tld", key, expected)
@@ -92,7 +85,7 @@ def test_get_text_for_resolver_with_unsupported_function(ens):
9285

9386

9487
@pytest.mark.asyncio
95-
@pytest.mark.parametrize("key,expected", SET_TEXT_RESOLVER_NOT_FOUND_CASES)
88+
@pytest.mark.parametrize("key,expected", GET_TEXT_TEST_CASES)
9689
async def test_async_set_text_resolver_not_found(async_ens, key, expected):
9790
with pytest.raises(ResolverNotFound):
9891
await async_ens.set_text("tld", key, expected)

tests/ens/test_wildcard_resolution.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def test_wildcard_resolution_with_extended_resolver_for_subdomains(ens, subdomai
1010
assert resolved_child_address == "0x000000000000000000000000000000000000dEaD"
1111

1212

13-
def test_async_wildcard_resolution_with_extended_resolver_for_parent_ens_domain(ens):
13+
def test_wildcard_resolution_with_extended_resolver_for_parent_ens_domain(ens):
1414
# validate `extended-resolver.eth` by asserting it returns the specified hard-coded address from
1515
# `tests/test_contracts/ExtendedResolver.sol` which requires a specific condition to be
1616
# met for the parent domain `extended-resolver.eth`
@@ -36,7 +36,7 @@ async def test_async_wildcard_resolution_with_extended_resolver_for_subdomains(
3636

3737

3838
@pytest.mark.asyncio
39-
async def test_wildcard_resolution_with_extended_resolver_for_parent_ens_domain(
39+
async def test_async_wildcard_resolution_with_extended_resolver_for_parent_ens_domain(
4040
async_ens,
4141
):
4242
# validate `extended-resolver.eth` by asserting it returns the specified hard-coded address from

web3/main.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133

134134
if TYPE_CHECKING:
135135
from web3.pm import PM # noqa: F401
136+
from web3._utils.empty import Empty # noqa: F401
136137

137138

138139
def get_default_modules() -> Dict[str, Union[Type[Module], Sequence[Any]]]:
@@ -249,7 +250,7 @@ def __init__(
249250
external_modules: Optional[
250251
Dict[str, Union[Type[Module], Sequence[Any]]]
251252
] = None,
252-
ens: Optional[Union[ENS, AsyncENS]] = None,
253+
ens: Union[ENS, AsyncENS, "Empty"] = empty,
253254
) -> None:
254255
self.manager = self.RequestManager(self, provider, middlewares)
255256
# this codec gets used in the module initialization,
@@ -350,16 +351,14 @@ def is_encodable(self, _type: TypeStr, value: Any) -> bool:
350351
return self.codec.is_encodable(_type, value)
351352

352353
@property
353-
def ens(self) -> Union[ENS, AsyncENS]:
354-
if self._ens is cast(ENS, empty):
355-
return ENS.fromWeb3(self)
356-
elif self._ens is cast(AsyncENS, empty) or self.eth.is_async:
357-
return AsyncENS.fromWeb3(self)
354+
def ens(self) -> Union[ENS, AsyncENS, "Empty"]:
355+
if self._ens is empty:
356+
return AsyncENS.fromWeb3(self) if self.eth.is_async else ENS.fromWeb3(self)
358357

359358
return self._ens
360359

361360
@ens.setter
362-
def ens(self, new_ens: Optional[Union[ENS, AsyncENS]]) -> None:
361+
def ens(self, new_ens: Union[ENS, AsyncENS, "Empty"]) -> None:
363362
self._ens = new_ens
364363

365364
@property

web3/pm.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
to_tuple,
3434
)
3535

36+
from ens import ENS
3637
from ethpm import (
3738
ASSETS_DIR,
3839
Package,
@@ -62,9 +63,6 @@
6263
from web3.module import (
6364
Module,
6465
)
65-
from web3.types import (
66-
ENS,
67-
)
6866

6967
# Package Management is still in alpha, and its API is likely to change, so it
7068
# is not automatically available on a web3 instance. To use the `PM` module,
@@ -383,7 +381,8 @@ def set_registry(self, address: Union[Address, ChecksumAddress, ENS]) -> None:
383381
self.registry = SimpleRegistry(cast(ChecksumAddress, address), self.w3)
384382
elif is_ens_name(address):
385383
self._validate_set_ens()
386-
addr_lookup = cast(ChecksumAddress, self.w3.ens.address(str(address)))
384+
ens = cast(ENS, self.w3.ens)
385+
addr_lookup = ens.address(str(address))
387386
if not addr_lookup:
388387
raise NameNotFound(
389388
f"No address found after ENS lookup for name: {address!r}."

0 commit comments

Comments
 (0)