Skip to content

Commit 44cbade

Browse files
committed
correct() updated to only return positive match, otherwise None is returned
1 parent bb634d2 commit 44cbade

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

language_tool_python/utils.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff 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

130133
def get_language_tool_download_path() -> str:

0 commit comments

Comments
 (0)