Skip to content

Commit 264145f

Browse files
committed
style: update to python 3.8 features
modernize type hints apply isort
1 parent 0bd9d8d commit 264145f

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/mnemonic/mnemonic.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2020
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2121
#
22+
from __future__ import annotations
2223

2324
import hashlib
2425
import hmac
2526
import itertools
2627
import os
2728
import secrets
29+
import typing as t
2830
import unicodedata
29-
from typing import AnyStr, List, Optional, TypeVar, Union
3031

31-
_T = TypeVar("_T")
3232
PBKDF2_ROUNDS = 2048
3333

3434

@@ -53,7 +53,7 @@ def b58encode(v: bytes) -> str:
5353

5454

5555
class Mnemonic(object):
56-
def __init__(self, language: str = "english", wordlist: Optional[List[str]] = None):
56+
def __init__(self, language: str = "english", wordlist: list[str] | None = None):
5757
self.radix = 2048
5858
self.language = language
5959

@@ -73,15 +73,15 @@ def __init__(self, language: str = "english", wordlist: Optional[List[str]] = No
7373
self.delimiter = "\u3000" if language == "japanese" else " "
7474

7575
@classmethod
76-
def list_languages(cls) -> List[str]:
76+
def list_languages(cls) -> list[str]:
7777
return [
7878
f.split(".")[0]
7979
for f in os.listdir(os.path.join(os.path.dirname(__file__), "wordlist"))
8080
if f.endswith(".txt")
8181
]
8282

8383
@staticmethod
84-
def normalize_string(txt: AnyStr) -> str:
84+
def normalize_string(txt: t.AnyStr) -> str:
8585
if isinstance(txt, bytes):
8686
utxt = txt.decode("utf8")
8787
elif isinstance(txt, str):
@@ -129,7 +129,7 @@ def generate(self, strength: int = 128) -> str:
129129
return self.to_mnemonic(secrets.token_bytes(strength // 8))
130130

131131
# Adapted from <http://tinyurl.com/oxmn476>
132-
def to_entropy(self, words: Union[List[str], str]) -> bytearray:
132+
def to_entropy(self, words: list[str] | str) -> bytearray:
133133
if not isinstance(words, list):
134134
words = words.split(" ")
135135
if len(words) not in [12, 15, 18, 21, 24]:

tools/generate_vectors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from random import choice, seed
55

66
from bip32utils import BIP32Key
7+
78
from mnemonic import Mnemonic
89

910

0 commit comments

Comments
 (0)