File tree Expand file tree Collapse file tree 1 file changed +15
-12
lines changed
Expand file tree Collapse file tree 1 file changed +15
-12
lines changed Original file line number Diff line number Diff line change @@ -113,18 +113,21 @@ def correct(text: str, matches: List[Match]) -> str:
113113 """
114114 ltext = list (text )
115115 matches = [match for match in matches if match .replacements ]
116- errors = [ltext [match .offset :match .offset + match .errorLength ]
117- for match in matches ]
118- correct_offset = 0
119- for n , match in enumerate (matches ):
120- frompos , topos = (correct_offset + match .offset ,
121- correct_offset + match .offset + match .errorLength )
122- if ltext [frompos :topos ] != errors [n ]:
123- continue
124- repl = match .replacements [0 ]
125- ltext [frompos :topos ] = list (repl )
126- correct_offset += len (repl ) - len (errors [n ])
127- return '' .join (ltext )
116+ if matches :
117+ errors = [ltext [match .offset :match .offset + match .errorLength ]
118+ for match in matches ]
119+ correct_offset = 0
120+ for n , match in enumerate (matches ):
121+ frompos , topos = (correct_offset + match .offset ,
122+ correct_offset + match .offset + match .errorLength )
123+ if ltext [frompos :topos ] != errors [n ]:
124+ continue
125+ repl = match .replacements [0 ]
126+ ltext [frompos :topos ] = list (repl )
127+ correct_offset += len (repl ) - len (errors [n ])
128+ return '' .join (ltext )
129+ else :
130+ return None
128131
129132
130133def get_language_tool_download_path () -> str :
You can’t perform that action at this time.
0 commit comments