Skip to content

Commit 7b215f2

Browse files
committed
Tighten ruff rules
1 parent c3b105e commit 7b215f2

File tree

7 files changed

+12
-8
lines changed

7 files changed

+12
-8
lines changed

exec_helpers/_ssh_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1884,9 +1884,10 @@ def exists(self, path: SupportPathT) -> bool:
18841884
"""
18851885
try:
18861886
self._sftp.lstat(pathlib.PurePath(path).as_posix())
1887-
return True
18881887
except OSError:
18891888
return False
1889+
else:
1890+
return True
18901891

18911892
def stat(self, path: SupportPathT) -> paramiko.sftp_attr.SFTPAttributes:
18921893
"""Get stat info for path with following symlinks.

exec_helpers/_ssh_helpers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ def _parse_ssh_config_file(file_path: pathlib.Path) -> paramiko.SSHConfig | None
4343
config = paramiko.SSHConfig()
4444
with file_path.open() as f_obj:
4545
config.parse(f_obj)
46-
return config
4746
except Exception:
48-
return None
47+
config = None
48+
49+
return config
4950

5051

5152
class SSHConfig:

exec_helpers/async_api/subprocess.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ async def poll_stderr() -> None:
331331
# Wait real timeout here
332332
exit_code: int = await asyncio.wait_for(async_result.interface.wait(), timeout=timeout)
333333
result.exit_code = exit_code
334-
return result
335334
except asyncio.TimeoutError as exc:
336335
# kill -9 for all subprocesses
337336
_subprocess_helpers.kill_proc_tree(async_result.interface.pid)
@@ -342,6 +341,8 @@ async def poll_stderr() -> None:
342341
timeout=timeout, # type: ignore[arg-type]
343342
) from exc
344343
result.exit_code = exit_signal
344+
else:
345+
return result
345346
finally:
346347
stdout_task.cancel()
347348
stderr_task.cancel()

exec_helpers/ssh_auth.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ def connect(
204204
if index != self.__key_index:
205205
self.__key_index = index
206206
LOGGER.debug(f"Main key has been updated, public key is: \n{self.public_key}")
207-
return
208207
except paramiko.PasswordRequiredException:
209208
if self.__password is None:
210209
LOGGER.exception("No password has been set!")
@@ -213,6 +212,8 @@ def connect(
213212
raise
214213
except (paramiko.AuthenticationException, paramiko.BadHostKeyException):
215214
continue
215+
else:
216+
return
216217
msg: str = "Connection using stored authentication info failed!"
217218
if log:
218219
LOGGER.exception(msg)

exec_helpers/subprocess.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ def close_streams() -> None:
346346
# Minimal timeout to complete polling
347347
concurrent.futures.wait([stdout_future, stderr_future], timeout=0.1)
348348
result.exit_code = exit_code
349-
return result
350349
except subprocess.TimeoutExpired as exc:
351350
# kill -9 for all subprocesses
352351
_subprocess_helpers.kill_proc_tree(async_result.interface.pid)
@@ -357,6 +356,8 @@ def close_streams() -> None:
357356
timeout=timeout, # type: ignore[arg-type]
358357
) from exc
359358
result.exit_code = exit_signal
359+
else:
360+
return result
360361
finally:
361362
stdout_future.cancel()
362363
stderr_future.cancel()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ extend-ignore = [
190190
"PLR0911", "PLR0912", "PLR0913", "PLR0915", "PLR2004", # refactor rules (too many statements/arguments/branches)
191191
"RET504", # Unnecessary variable assignment before return statement
192192
"SIM108", # Use ternary operator,
193-
"TRY002", "TRY003", "TRY300", "TRY301", "TRY400", # do not raise `Exception`, long messages prepare outside, ...
193+
"TRY003", # long messages prepare outside, ...
194194
"PTH118", "PTH119", # `os.path.join()`, `os.path.basename()` should be replaced
195195
]
196196

tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ deps =
117117
-r{toxinidir}/mypy_requirements.txt
118118
-r{toxinidir}/CI_REQUIREMENTS.txt
119119
commands =
120-
python setup.py --version clean
121120
mypy --install-types --non-interactive --xslt-html-report mypy_report -p exec_helpers
122121

123122
[testenv:isort]

0 commit comments

Comments
 (0)