Skip to content

Commit 20757b1

Browse files
authored
Breaking/add remaining breaking changes for major (#333)
* breaking: remove deprecated ``str`` support in mnemonic * breaking: bump eth-keyfile lower pin for new major * chore: remove unused imports * updates from comments on PR #333
1 parent 63a9fc5 commit 20757b1

8 files changed

Lines changed: 15 additions & 75 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,6 @@ crashlytics-build.properties
110110
fabric.properties
111111

112112
# END JetBrains section
113+
114+
# uv
115+
uv.lock

eth_account/account.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def decrypt(keyfile_json: str | dict[str, Any], password: str) -> HexBytes:
207207
# type ignored because eth_keyfile appears to be using the wrong type for
208208
# the password arg.
209209
# once fixed there, this should error and can be removed
210-
return HexBytes(decode_keyfile_json(keyfile, password_bytes)) # type: ignore[arg-type] # noqa: E501
210+
return HexBytes(decode_keyfile_json(keyfile, password_bytes))
211211

212212
@classmethod
213213
def encrypt(
@@ -277,7 +277,10 @@ def encrypt(
277277
# the password arg.
278278
# once fixed there, this should error and can be removed
279279
return create_keyfile_json(
280-
key_bytes, password_bytes, kdf=kdf, iterations=iterations # type: ignore[arg-type] # noqa: E501
280+
key_bytes,
281+
password_bytes,
282+
kdf=kdf,
283+
iterations=iterations,
281284
)
282285

283286
@combomethod
@@ -384,7 +387,7 @@ def create_with_mnemonic(
384387
self,
385388
passphrase: str = "",
386389
num_words: int = 12,
387-
language: Language | str = Language.ENGLISH,
390+
language: Language = Language.ENGLISH,
388391
account_path: str = ETHEREUM_DEFAULT_PATH,
389392
) -> tuple[LocalAccount, str]:
390393
r"""
@@ -400,9 +403,7 @@ def create_with_mnemonic(
400403
:param int num_words: Number of words to use with seed phrase.
401404
Default is 12 words.
402405
Must be one of [12, 15, 18, 21, 24].
403-
:param (Language, str) language: Language to use for BIP39 mnemonic seed phrase.
404-
The use of a string is deprecated and will be
405-
removed in a future version.
406+
:param Language language: Language to use for BIP39 mnemonic seed phrase.
406407
:param str account_path: Specify an alternate HD path for deriving the
407408
seed using BIP32 HD wallet key derivation.
408409
:returns: A tuple consisting of an object with private key and

eth_account/hdaccount/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
from typing import (
2-
Union,
3-
)
4-
import warnings
5-
61
from eth_utils import (
72
ValidationError,
83
)
@@ -21,7 +16,7 @@
2116
ETHEREUM_DEFAULT_PATH = "m/44'/60'/0'/0/0"
2217

2318

24-
def generate_mnemonic(num_words: int, lang: Language | str) -> str:
19+
def generate_mnemonic(num_words: int, lang: Language) -> str:
2520
return Mnemonic(lang).generate(num_words)
2621

2722

eth_account/hdaccount/mnemonic.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
Path,
2626
)
2727
import secrets
28-
import warnings
2928

3029
from bitarray import (
3130
bitarray,
@@ -110,23 +109,8 @@ class Mnemonic:
110109
b'\x97ii\x07\x12\xf0$\x81\x98\xb6?\x07\x08t7\x18d\x87\xe1\x7f\xbe\xbaL\xb4i%\xeb\x12\xce\xe2h\x1c\xb2\x19\x13\xfb9wtoV\x9c\xb8\xdf;5\xba4X\xa3\xd6b`|\xdc\xb1\x10\xb0\xeeS\x86\x95\xd75'
111110
""" # noqa: E501
112111

113-
def __init__(self, raw_language: Language | str = Language.ENGLISH):
114-
if isinstance(raw_language, str):
115-
warnings.warn(
116-
"The language parameter should be a Language enum, not a string. "
117-
"This will be enforced in a future version.",
118-
DeprecationWarning,
119-
stacklevel=2,
120-
)
121-
122-
language = raw_language.lower().replace(" ", "_")
123-
languages = Mnemonic.list_languages()
124-
if language not in languages:
125-
raise ValidationError(
126-
f"Invalid language choice '{language}', must be one of {languages}"
127-
)
128-
else:
129-
language = raw_language.value
112+
def __init__(self, raw_language: Language = Language.ENGLISH):
113+
language = raw_language.value
130114
self.language = language
131115
self.wordlist = get_wordlist(self.language)
132116

newsfragments/333.breaking.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bump ``eth-keyfile`` lower pin for new major version. Remove deprecated ``str`` support for mnemonic, opt for enum support only.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
install_requires=[
5353
"bitarray>=2.4.0",
5454
"eth-abi>=4.0.0-b.2",
55-
"eth-keyfile>=0.7.0, <0.9.0",
55+
"eth-keyfile>=0.9.0",
5656
"eth-keys>=0.4.0",
5757
"eth-rlp>=2.1.0",
5858
"eth-utils>=5.3.0",

tests/core/test_hdaccount.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,3 @@ def test_bad_account_path1():
9292
def test_bad_account_path2():
9393
with pytest.raises(ValidationError, match="Path.*is not valid.*"):
9494
Account.create_with_mnemonic(account_path="m/not/an/account/path")
95-
96-
97-
def test_unknown_language():
98-
with pytest.raises(
99-
ValidationError, match="Invalid language choice 'pig_latin', must be one of.*"
100-
):
101-
with pytest.warns(
102-
DeprecationWarning,
103-
match="The language parameter should be a Language enum, not a string*.",
104-
):
105-
Account.create_with_mnemonic(language="pig latin")
106-
107-
108-
def test_known_language_as_string_warns():
109-
with pytest.warns(
110-
DeprecationWarning,
111-
match="The language parameter should be a Language enum, not a string*.",
112-
):
113-
Account.create_with_mnemonic(language="spanish")

tests/core/test_mnemonic.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ def test_detection(language, word):
6767
def test_undetected_language():
6868
with pytest.raises(ValidationError):
6969
Mnemonic.detect_language("xxxxxxx")
70-
with pytest.raises(ValidationError):
71-
with pytest.warns(
72-
DeprecationWarning,
73-
match="The language parameter should be a Language enum, not a string",
74-
):
75-
Mnemonic("xxxxxxx")
7670

7771

7872
def test_expand_word():
@@ -136,25 +130,6 @@ def test_generation_with_enum(lang, num_words):
136130
assert len(Mnemonic.to_seed(mnemonic)) == 64
137131

138132

139-
@pytest.mark.parametrize("lang", Mnemonic.list_languages())
140-
@pytest.mark.parametrize("num_words", [12, 15, 18, 21, 24])
141-
def test_generation_with_string(lang, num_words):
142-
with pytest.warns(DeprecationWarning):
143-
m = Mnemonic(lang)
144-
mnemonic = m.generate(num_words)
145-
assert m.is_mnemonic_valid(mnemonic)
146-
try:
147-
assert Mnemonic.detect_language(mnemonic) == Language(lang)
148-
except AssertionError:
149-
# NOTE: Sometimes traditional chinese can return characters that are also
150-
# valid simplified chinese characters. In that scenario, the detection
151-
# algorithm will assume simplified.
152-
if lang != "chinese_traditional":
153-
raise
154-
assert Mnemonic.detect_language(mnemonic) == Language.CHINESE_SIMPLIFIED
155-
assert len(Mnemonic.to_seed(mnemonic)) == 64
156-
157-
158133
@pytest.mark.parametrize(
159134
"entropy,expected_mnemonic,expected_seed",
160135
[

0 commit comments

Comments
 (0)