Skip to content

Commit 2f3cf5b

Browse files
committed
correct() updated to return None in case of correct word submit for test and str() for lack of suggestion, i.e. gibberish submit
1 parent 44cbade commit 2f3cf5b

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

language_tool_python/utils.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"""Utility functions for the LanguageTool library."""
2-
31
from typing import List, Tuple, Optional
42
from shutil import which
53

@@ -73,15 +71,6 @@ class PathError(LanguageToolError):
7371
pass
7472

7573

76-
class RateLimitError(LanguageToolError):
77-
"""
78-
Exception raised for errors related to rate limiting in the LanguageTool server.
79-
This exception is a subclass of `LanguageToolError` and is used to indicate
80-
issues such as exceeding the allowed number of requests to the public API without a key.
81-
"""
82-
pass
83-
84-
8574
def parse_url(url_str: str) -> str:
8675
"""
8776
Parse the given URL string and ensure it has a scheme.
@@ -112,24 +101,26 @@ def correct(text: str, matches: List[Match]) -> str:
112101
:rtype: str
113102
"""
114103
ltext = list(text)
115-
matches = [match for match in matches if match.replacements]
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)
104+
if len(matches):
105+
matches = [match for match in matches if match.replacements]
106+
if matches:
107+
errors = [ltext[match.offset:match.offset + match.errorLength]
108+
for match in matches]
109+
correct_offset = 0
110+
for n, match in enumerate(matches):
111+
frompos, topos = (correct_offset + match.offset,
112+
correct_offset + match.offset + match.errorLength)
113+
if ltext[frompos:topos] != errors[n]:
114+
continue
115+
repl = match.replacements[0]
116+
ltext[frompos:topos] = list(repl)
117+
correct_offset += len(repl) - len(errors[n])
118+
return ''.join(ltext)
119+
else:
120+
return str()
129121
else:
130122
return None
131123

132-
133124
def get_language_tool_download_path() -> str:
134125
"""
135126
Get the download path for LanguageTool.

0 commit comments

Comments
 (0)