Skip to content

Commit 3315fc1

Browse files
committed
Updates from conversation in pr #2452
1 parent b6a7e04 commit 3315fc1

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

ens/main.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,10 @@ def setup_name(
261261

262262
def resolve(self, name: str, get: str = 'addr') -> Optional[Union[ChecksumAddress, str]]:
263263
warnings.warn(
264-
"In v6, the resolve() method will be made internal and renamed to _resolve(). The "
265-
"'get' param name will also change to 'fn_name'.",
264+
"In v6, the `ENS.resolve()` method will be made internal and renamed to "
265+
"`_resolve()`. It is recommended to use the abstracted resolve functionality of "
266+
"`ENS.address()` for forward resolution, and `ENS.name()` for reverse resolution "
267+
"instead.",
266268
category=DeprecationWarning,
267269
)
268270

@@ -278,12 +280,15 @@ def resolve(self, name: str, get: str = 'addr') -> Optional[Union[ChecksumAddres
278280
else:
279281
return None
280282

281-
def resolver(self, normal_name: str) -> Optional['Contract']:
282-
warnings.warn(
283-
"The function signature for resolver() will change in v6 to accept 'name' as a param, "
284-
"over 'normalized_name', and the method will normalize the name internally.",
285-
category=FutureWarning,
286-
)
283+
def resolver(self, normal_name: str, name: str = None) -> Optional['Contract']:
284+
if not name:
285+
warnings.warn(
286+
"The function signature for resolver() will change in v6 to accept `name` as a "
287+
"the positional argument, over `normal_name`, and the method will instead "
288+
"normalize the name internally. To suppress warnings for now, `name` may be passed "
289+
"in as a keyword argument.",
290+
category=FutureWarning,
291+
)
287292

288293
resolver_addr = self.ens.caller.resolver(normal_name_to_hash(normal_name))
289294
if is_none_or_zero_address(resolver_addr):

tests/ens/test_v6_warnings.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
import pytest
2+
import warnings
23

34

45
def test_resolve_deprecation_warning(ens):
56
with pytest.warns(
67
DeprecationWarning,
7-
match="In v6, the resolve\\(\\) method will be made internal and renamed to "
8-
"_resolve\\(\\). The 'get' param name will also change to 'fn_name'.",
8+
match="In v6, the `ENS.resolve\\(\\)` method will be made internal and renamed to "
9+
"`_resolve\\(\\)`. It is recommended to use the abstracted resolve functionality of "
10+
"`ENS.address\\(\\)` for forward resolution, and `ENS.name\\(\\)` for reverse "
11+
"resolution instead."
912
):
1013
ens.resolve('tester.eth')
1114

1215

1316
def test_resolver_future_warning(ens):
1417
with pytest.warns(
1518
FutureWarning,
16-
match="The function signature for resolver\\(\\) will change in v6 to accept 'name' as a "
17-
"param, over 'normalized_name', and the method will normalize the name internally.",
19+
match="The function signature for resolver\\(\\) will change in v6 to accept `name` as a "
20+
"the positional argument, over `normal_name`, and the method will instead "
21+
"normalize the name internally. To suppress warnings for now, `name` may be passed "
22+
"in as a keyword argument.",
1823
):
1924
ens.resolver('tester.eth')
25+
26+
# assert no warning when `name` kwarg is passed in
27+
with warnings.catch_warnings():
28+
warnings.simplefilter("error") # turn all warnings to errors
29+
ens.resolver('tester.eth', name='tester.eth')

0 commit comments

Comments
 (0)