Skip to content

Commit b1e23b3

Browse files
committed
Allow updating to v6 method signature for ENS.resolver()
1 parent 3315fc1 commit b1e23b3

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

ens/main.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,22 @@ def resolve(self, name: str, get: str = 'addr') -> Optional[Union[ChecksumAddres
280280
else:
281281
return None
282282

283-
def resolver(self, normal_name: str, name: str = None) -> Optional['Contract']:
283+
def resolver(self, normal_name: str = None, name: str = None) -> Optional['Contract']:
284284
if not name:
285285
warnings.warn(
286286
"The function signature for resolver() will change in v6 to accept `name` as a "
287287
"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.",
288+
"normalize the name internally. You may migrate to using `name` by passing it in "
289+
"as a keyword, e.g. resolver(name=\"ensname.eth\").",
290290
category=FutureWarning,
291291
)
292+
else:
293+
if normal_name:
294+
raise TypeError(
295+
"Only supply one positional argument or the `name` keyword, e.g. "
296+
"resolver(\"ensname.eth\") or resolver(name=\"ensname.eth\")."
297+
)
298+
normal_name = normalize_name(name)
292299

293300
resolver_addr = self.ens.caller.resolver(normal_name_to_hash(normal_name))
294301
if is_none_or_zero_address(resolver_addr):

tests/ens/test_v6_warnings.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,28 @@ def test_resolve_deprecation_warning(ens):
1010
"`ENS.address\\(\\)` for forward resolution, and `ENS.name\\(\\)` for reverse "
1111
"resolution instead."
1212
):
13-
ens.resolve('tester.eth')
13+
ens.resolve("tester.eth")
1414

1515

16-
def test_resolver_future_warning(ens):
16+
def test_resolver_future_warning_when_name_is_missing(ens):
1717
with pytest.warns(
1818
FutureWarning,
1919
match="The function signature for resolver\\(\\) will change in v6 to accept `name` as a "
2020
"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.",
21+
"normalize the name internally. You may migrate to using `name` by passing it in "
22+
"as a keyword, e.g. resolver\\(name=\"ensname.eth\"\\).",
2323
):
24-
ens.resolver('tester.eth')
24+
assert ens.resolver("eth")
2525

26-
# assert no warning when `name` kwarg is passed in
26+
# assert no warning when `name` is passed in as a kwarg
2727
with warnings.catch_warnings():
2828
warnings.simplefilter("error") # turn all warnings to errors
29-
ens.resolver('tester.eth', name='tester.eth')
29+
assert ens.resolver(name="EtH")
30+
31+
# assert TypeError if both arguments passed in
32+
with pytest.raises(
33+
TypeError,
34+
match="Only supply one positional argument or the `name` keyword, e.g. resolver\\("
35+
"\"ensname.eth\"\\) or resolver\\(name=\"ensname.eth\"\\).",
36+
):
37+
ens.resolver("eth", name="EtH")

0 commit comments

Comments
 (0)