@@ -20,6 +20,7 @@ class DAWG:
20
20
"""
21
21
Base DAWG wrapper.
22
22
"""
23
+
23
24
dct : wrapper .Dictionary | None
24
25
25
26
def __init__ (self ) -> None :
@@ -41,7 +42,6 @@ def _has_value(self, index: int) -> bool:
41
42
return self .dct .has_value (index )
42
43
43
44
def _similar_keys (self , current_prefix : str , key : str , index : int , replace_chars : CompiledReplaces ) -> list [str ]:
44
-
45
45
res = []
46
46
start_pos = len (current_prefix )
47
47
end_pos = len (key )
@@ -51,7 +51,7 @@ def _similar_keys(self, current_prefix: str, key: str, index: int, replace_chars
51
51
b_step = key [word_pos ].encode ("utf8" )
52
52
53
53
if b_step in replace_chars :
54
- for ( b_replace_char , u_replace_char ) in replace_chars [b_step ]:
54
+ for b_replace_char , u_replace_char in replace_chars [b_step ]:
55
55
next_index = index
56
56
57
57
next_index = self .dct .follow_bytes (b_replace_char , next_index )
@@ -89,22 +89,18 @@ def similar_keys(self, key: str, replaces: CompiledReplaces):
89
89
90
90
@classmethod
91
91
def compile_replaces (cls , replaces : Replaces ) -> CompiledReplaces :
92
-
93
- for k ,v in replaces .items ():
92
+ for k , v in replaces .items ():
94
93
if len (k ) != 1 :
95
94
msg = "Keys must be single-char unicode strings."
96
95
raise ValueError (msg )
97
- if ( isinstance (v , str ) and len (v ) != 1 ) :
96
+ if isinstance (v , str ) and len (v ) != 1 :
98
97
msg = "Values must be single-char unicode strings or non-empty lists of such."
99
98
raise ValueError (msg )
100
99
if isinstance (v , list ) and (any (len (v_entry ) != 1 for v_entry in v ) or len (v ) < 1 ):
101
100
msg = "Values must be single-char unicode strings or non-empty lists of such."
102
101
raise ValueError (msg )
103
102
104
- return {
105
- k .encode ("utf8" ): [(v_entry .encode ("utf8" ), v_entry ) for v_entry in v ]
106
- for k , v in replaces .items ()
107
- }
103
+ return {k .encode ("utf8" ): [(v_entry .encode ("utf8" ), v_entry ) for v_entry in v ] for k , v in replaces .items ()}
108
104
109
105
def prefixes (self , key : str | bytes ) -> list [str ]:
110
106
"""
@@ -133,6 +129,7 @@ class CompletionDAWG(DAWG):
133
129
"""
134
130
DAWG with key completion support.
135
131
"""
132
+
136
133
dct : wrapper .Dictionary
137
134
guide : wrapper .Guide | None
138
135
@@ -331,8 +328,13 @@ def iteritems(self, prefix: str | bytes = "") -> Generator[tuple[str, bytes], No
331
328
def _has_value (self , index : int ) -> int | None :
332
329
return self .dct .follow_bytes (PAYLOAD_SEPARATOR , index )
333
330
334
- def _similar_items (self , current_prefix : str , key : str , index : int , replace_chars : CompiledReplaces ) -> list [tuple [str , bytes ]]:
335
-
331
+ def _similar_items (
332
+ self ,
333
+ current_prefix : str ,
334
+ key : str ,
335
+ index : int ,
336
+ replace_chars : CompiledReplaces ,
337
+ ) -> list [tuple [str , bytes ]]:
336
338
res = []
337
339
start_pos = len (current_prefix )
338
340
end_pos = len (key )
@@ -342,7 +344,7 @@ def _similar_items(self, current_prefix: str, key: str, index: int, replace_char
342
344
b_step = key [word_pos ].encode ("utf8" )
343
345
344
346
if b_step in replace_chars :
345
- for ( b_replace_char , u_replace_char ) in replace_chars [b_step ]:
347
+ for b_replace_char , u_replace_char in replace_chars [b_step ]:
346
348
next_index = index
347
349
348
350
next_index = self .dct .follow_bytes (b_replace_char , next_index )
@@ -378,7 +380,13 @@ def similar_items(self, key: str, replaces: CompiledReplaces) -> list[tuple[str,
378
380
"""
379
381
return self ._similar_items ("" , key , self .dct .ROOT , replaces )
380
382
381
- def _similar_item_values (self , start_pos : int , key : str , index : int , replace_chars : CompiledReplaces ) -> list [bytes ]:
383
+ def _similar_item_values (
384
+ self ,
385
+ start_pos : int ,
386
+ key : str ,
387
+ index : int ,
388
+ replace_chars : CompiledReplaces ,
389
+ ) -> list [bytes ]:
382
390
res = []
383
391
end_pos = len (key )
384
392
word_pos = start_pos
@@ -387,7 +395,7 @@ def _similar_item_values(self, start_pos: int, key: str, index: int, replace_cha
387
395
b_step = key [word_pos ].encode ("utf8" )
388
396
389
397
if b_step in replace_chars :
390
- for ( b_replace_char , _u_replace_char ) in replace_chars [b_step ]:
398
+ for b_replace_char , _u_replace_char in replace_chars [b_step ]:
391
399
next_index = index
392
400
393
401
next_index = self .dct .follow_bytes (b_replace_char , next_index )
0 commit comments