Skip to content

Commit 1dabc06

Browse files
authored
Merge pull request jxmorris12#135 from mdevolde/ruff
feat (ruff): added some rules to ruff (N, S, BLE), corrected S and N warns
2 parents 2e77067 + be13e8b commit 1dabc06

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

language_tool_python/download_lt.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def confirm_java_compatibility(
101101

102102
logger.debug("Found java executable at %s", java_path)
103103

104-
output = subprocess.check_output(
104+
output = subprocess.check_output( # noqa: S603 # java_path come from shutil.which -> trusted
105105
[java_path, "-version"],
106106
stderr=subprocess.STDOUT,
107107
universal_newlines=True,
@@ -170,10 +170,15 @@ def http_get(
170170
:type out_file: IO[bytes]
171171
:param proxies: Optional dictionary of proxies to use for the request.
172172
:type proxies: Optional[Dict[str, str]]
173+
:raises TimeoutError: If the request times out.
173174
:raises PathError: If the file could not be found at the given URL (HTTP 404).
174175
"""
175176
logger.info("Starting download from %s", url)
176-
req = requests.get(url, stream=True, proxies=proxies)
177+
try:
178+
req = requests.get(url, stream=True, proxies=proxies, timeout=60)
179+
except requests.exceptions.Timeout as e:
180+
err = f"Request to {url} timed out."
181+
raise TimeoutError(err) from e
177182
content_length = req.headers.get("Content-Length")
178183
total = int(content_length) if content_length is not None else None
179184
if req.status_code == 404:

language_tool_python/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ def _start_local_server(self) -> None:
628628
)
629629
raise PathError(err) from e
630630
else:
631-
self._server = subprocess.Popen(
631+
self._server = subprocess.Popen( # noqa: S603 # server_cmd is constructed internally -> trusted
632632
server_cmd,
633633
stdin=subprocess.PIPE,
634634
stdout=subprocess.DEVNULL,

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ packages = { find = { include = ["language_tool_python*"] } }
7474
language_tool_python = ["py.typed", "logging.toml"]
7575

7676
[tool.ruff.lint]
77-
select = ["F", "W", "I", "B", "SIM", "RET", "Q"]
77+
select = ["F", "W", "I", "B", "SIM", "RET", "Q", "N", "S", "BLE"]
78+
79+
[tool.ruff.lint.per-file-ignores]
80+
"tests/*.py" = ["S101"]
7881

7982
[tool.mypy]
8083
files = ["language_tool_python"]

tests/test_major_functionality.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ def test_session_only_new_spellings():
370370
def test_disabled_rule_in_config():
371371
import language_tool_python
372372

373-
GRAMMAR_TOOL_CONFIG = {"disabledRuleIds": ["MORFOLOGIK_RULE_EN_US"]}
374-
with language_tool_python.LanguageTool("en-US", config=GRAMMAR_TOOL_CONFIG) as tool:
373+
grammar_tool_config = {"disabledRuleIds": ["MORFOLOGIK_RULE_EN_US"]}
374+
with language_tool_python.LanguageTool("en-US", config=grammar_tool_config) as tool:
375375
text = "He realised that the organization was in jeopardy."
376376
matches = tool.check(text)
377377
assert len(matches) == 0

0 commit comments

Comments
 (0)