55import os
66from typing import (
77 Any ,
8- Dict ,
9- List ,
108 Literal ,
11- Optional ,
12- Set ,
13- Tuple ,
14- Union ,
159)
1610
1711from pyunormalize import (
2721
2822
2923def _json_list_mapping_to_dict (
30- f : Dict [str , Any ],
24+ f : dict [str , Any ],
3125 list_mapped_key : str ,
32- ) -> Dict [str , Any ]:
26+ ) -> dict [str , Any ]:
3327 """
3428 Takes a `[key, [value]]` mapping from the original ENS spec json files and turns it
3529 into a `{key: value}` mapping.
@@ -67,17 +61,17 @@ class TokenType(Enum):
6761class Token :
6862 type : Literal [TokenType .TEXT , TokenType .EMOJI ]
6963 _original_text : str
70- _original_codepoints : List [int ]
71- _normalized_codepoints : Optional [ List [ int ]] = None
64+ _original_codepoints : list [int ]
65+ _normalized_codepoints : list [ int ] | None = None
7266
7367 restricted : bool = False
7468
75- def __init__ (self , codepoints : List [int ]) -> None :
69+ def __init__ (self , codepoints : list [int ]) -> None :
7670 self ._original_codepoints = codepoints
7771 self ._original_text = "" .join (chr (cp ) for cp in codepoints )
7872
7973 @property
80- def codepoints (self ) -> List [int ]:
74+ def codepoints (self ) -> list [int ]:
8175 return (
8276 self ._normalized_codepoints
8377 if self ._normalized_codepoints
@@ -99,12 +93,12 @@ class TextToken(Token):
9993
10094class Label :
10195 type : str
102- tokens : List [Token ]
96+ tokens : list [Token ]
10397
10498 def __init__ (
10599 self ,
106100 type : str = None ,
107- tokens : List [Token ] = None ,
101+ tokens : list [Token ] = None ,
108102 ) -> None :
109103 self .type = type
110104 self .tokens = tokens
@@ -118,9 +112,9 @@ def text(self) -> str:
118112
119113
120114class ENSNormalizedName :
121- labels : List [Label ]
115+ labels : list [Label ]
122116
123- def __init__ (self , normalized_labels : List [Label ]) -> None :
117+ def __init__ (self , normalized_labels : list [Label ]) -> None :
124118 self .labels = normalized_labels
125119
126120 @property
@@ -140,28 +134,28 @@ def as_text(self) -> str:
140134}
141135
142136
143- def _extract_valid_codepoints () -> Set [int ]:
137+ def _extract_valid_codepoints () -> set [int ]:
144138 all_valid = set ()
145139 for _name , valid_cps in VALID_BY_GROUPS .items ():
146140 all_valid .update (valid_cps )
147141 all_valid .update (map (ord , NFD ("" .join (map (chr , all_valid )))))
148142 return all_valid
149143
150144
151- def _construct_whole_confusable_map () -> Dict [int , Set [str ]]:
145+ def _construct_whole_confusable_map () -> dict [int , set [str ]]:
152146 """
153147 Create a mapping, per confusable, that contains all the groups in the cp's whole
154148 confusable excluding the confusable extent of the cp itself - as per the spec at
155149 https://docs.ens.domains/ens-improvement-proposals/ensip-15-normalization-standard
156150 """
157- whole_map : Dict [int , Set [str ]] = {}
151+ whole_map : dict [int , set [str ]] = {}
158152 for whole in NORMALIZATION_SPEC ["wholes" ]:
159- whole_confusables : Set [int ] = set (whole ["valid" ] + whole ["confused" ])
160- confusable_extents : List [ Tuple [ Set [int ], Set [str ]]] = []
153+ whole_confusables : set [int ] = set (whole ["valid" ] + whole ["confused" ])
154+ confusable_extents : list [ tuple [ set [int ], set [str ]]] = []
161155
162156 for confusable_cp in whole_confusables :
163157 # create confusable extents for all whole confusables
164- groups : Set [str ] = set ()
158+ groups : set [str ] = set ()
165159 for gn , gv in VALID_BY_GROUPS .items ():
166160 if confusable_cp in gv :
167161 groups .add (gn )
@@ -181,7 +175,7 @@ def _construct_whole_confusable_map() -> Dict[int, Set[str]]:
181175 confusable_extents .append (({confusable_cp }, groups ))
182176
183177 for confusable_cp in whole_confusables :
184- confusable_cp_extent_groups : Set [str ] = set ()
178+ confusable_cp_extent_groups : set [str ] = set ()
185179
186180 if confusable_cp in whole ["confused" ]:
187181 whole_map [confusable_cp ] = set ()
@@ -209,13 +203,13 @@ def _is_fenced(cp: int) -> bool:
209203 return cp in [fenced [0 ] for fenced in NORMALIZATION_SPEC ["fenced" ]]
210204
211205
212- def _codepoints_to_text (cps : Union [ List [ List [ int ]], List [int ] ]) -> str :
206+ def _codepoints_to_text (cps : list [ list [ int ]] | list [int ]) -> str :
213207 return "" .join (
214208 chr (cp ) if isinstance (cp , int ) else _codepoints_to_text (cp ) for cp in cps
215209 )
216210
217211
218- def _validate_tokens_and_get_label_type (tokens : List [Token ]) -> str :
212+ def _validate_tokens_and_get_label_type (tokens : list [Token ]) -> str :
219213 """
220214 Validate tokens and return the label type.
221215
@@ -388,7 +382,7 @@ def _validate_tokens_and_get_label_type(tokens: List[Token]) -> str:
388382 return chars_group_name
389383
390384
391- def _build_and_validate_label_from_tokens (tokens : List [Token ]) -> Label :
385+ def _build_and_validate_label_from_tokens (tokens : list [Token ]) -> Label :
392386 for token in tokens :
393387 if token .type == TokenType .TEXT :
394388 # apply NFC normalization to text tokens
@@ -404,7 +398,7 @@ def _build_and_validate_label_from_tokens(tokens: List[Token]) -> Label:
404398 return label
405399
406400
407- def _buffer_codepoints_to_chars (buffer : Union [ List [ int ], List [ List [int ] ]]) -> str :
401+ def _buffer_codepoints_to_chars (buffer : list [ int ] | list [ list [int ]]) -> str :
408402 return "" .join (
409403 "" .join (chr (c ) for c in char ) if isinstance (char , list ) else chr (char )
410404 for char in buffer
@@ -438,8 +432,8 @@ def normalize_name_ensip15(name: str) -> ENSNormalizedName:
438432 # _input takes the label and breaks it into a list of unicode code points
439433 # e.g. "xyz👨🏻" -> [120, 121, 122, 128104, 127995]
440434 _input = [ord (c ) for c in label_str ]
441- buffer : List [int ] = []
442- tokens : List [Token ] = []
435+ buffer : list [int ] = []
436+ tokens : list [Token ] = []
443437
444438 while len (_input ) > 0 :
445439 emoji_codepoint = None
0 commit comments