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
2324import hashlib
2425import hmac
2526import itertools
2627import os
2728import secrets
29+ import typing as t
2830import unicodedata
29- from typing import AnyStr , List , Optional , TypeVar , Union
3031
31- _T = TypeVar ("_T" )
3232PBKDF2_ROUNDS = 2048
3333
3434
@@ -53,7 +53,7 @@ def b58encode(v: bytes) -> str:
5353
5454
5555class 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 ]:
0 commit comments