Skip to content

Commit 46b53a8

Browse files
committed
Merge branch 'mr/fix_RUF021_rule' into 'master'
Fix RUF021 rule See merge request it/e3-core!413
2 parents 062bcf6 + c8dc70f commit 46b53a8

9 files changed

Lines changed: 19 additions & 27 deletions

File tree

src/e3/anod/store/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import contextlib
56
import json
67
import os
78
import sqlite3
@@ -2386,12 +2387,10 @@ def bulk_update_from_store(
23862387
query.update(unprocessed_query)
23872388

23882389
if not query["bid"] and "setup" in query:
2389-
try:
2390+
with contextlib.suppress(StoreError):
23902391
query["bid"] = from_store.get_latest_build_info(
23912392
setup=query["setup"], date=query.get("date")
23922393
)["_id"]
2393-
except StoreError:
2394-
pass
23952394

23962395
if query.get("bid"):
23972396
required_bids.add(query["bid"])

src/e3/anod/store/interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
if TYPE_CHECKING:
1212
import os
13+
from pathlib import Path
1314
from typing import Any, Literal, TypedDict, TypeVar
1415

1516
from e3.anod.store.buildinfo import BuildInfoDict
1617
from e3.anod.store.component import ComponentDict
1718
from e3.anod.store.file import FileDict
18-
from pathlib import Path
1919

2020
StoreContextManagerType = TypeVar(
2121
"StoreContextManagerType", bound="_StoreContextManager"

src/e3/archive.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,8 @@ def check_type(
129129
:return: the file extension
130130
"""
131131
# Check extension
132-
if (
133-
filename.endswith(".tar.gz")
134-
or filename.endswith(".tgz")
135-
or (force_extension is not None and force_extension in [".tar.gz", ".tgz"])
132+
if filename.endswith((".tar.gz", ".tgz")) or (
133+
force_extension is not None and force_extension in [".tar.gz", ".tgz"]
136134
):
137135
return "tar.gz"
138136
if filename.endswith(".tar.bz2") or (

src/e3/collection/dag.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,10 @@ def next_element(
8787
for node in self.non_visited:
8888
minimal_cycle = self.dag.shortest_path(node, node)
8989
if minimal_cycle is not None:
90-
raise DAGError(
91-
"cycle detected: {}".format(
92-
" -> ".join(
93-
[str(vertex_id) for vertex_id in minimal_cycle]
94-
)
95-
)
90+
msg = "cycle detected: {}".format(
91+
" -> ".join([str(vertex_id) for vertex_id in minimal_cycle])
9692
)
93+
raise DAGError(msg)
9794
msg = "cycle detected (unknown error)"
9895
raise DAGError(msg)
9996

@@ -475,7 +472,7 @@ def shortest_path(
475472
# We have found our shortest path, so break
476473
if u == path_source:
477474
break
478-
elif u is None:
475+
if u is None:
479476
continue
480477

481478
for u_pred in self.get_predecessors(u):

src/e3/fs.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import shutil
1212
import stat
1313
import sys
14-
from collections.abc import Iterable
1514
from pathlib import Path
1615
from platform import python_version
1716
from typing import TYPE_CHECKING, NamedTuple
@@ -33,7 +32,7 @@
3332
TIMESTAMP_TOLERANCE = 0.001
3433

3534
if TYPE_CHECKING:
36-
from collections.abc import Callable, Sequence
35+
from collections.abc import Callable, Iterable, Sequence
3736
from typing import Any
3837

3938

@@ -621,12 +620,12 @@ def splitall(path: str | Path) -> tuple[str, ...]:
621620
# os.path.split('/') -> ('/', '')
622621
dirnames.append(head)
623622
break
624-
elif tail == path:
623+
if tail == path:
625624
# relative paths
626625
# os.path.split('..') -> ('', '..')
627626
dirnames.append(tail)
628627
break
629-
elif tail == "":
628+
if tail == "":
630629
# ending with a directory separator
631630
# os.path.split('a/b/c/') -> ('a/b/c', '')
632631
pass

src/e3/net/token.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import base64
6+
import contextlib
67
import json
78

89
from e3.date import utc_timestamp
@@ -26,10 +27,8 @@ def get_payload(token: str) -> dict:
2627
rem = len(payload) % 4
2728
if rem > 0:
2829
payload += "=" * (4 - rem)
29-
try:
30+
with contextlib.suppress(ValueError, TypeError):
3031
data = json.loads(base64.urlsafe_b64decode(payload).decode("utf-8"))
31-
except (ValueError, TypeError):
32-
pass
3332
return data
3433

3534

src/e3/python/pypi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def get_pip_env(platform: str, python_version: Version) -> dict[str, str]:
7474
result["sys_platform"] = "darwin"
7575
elif platform.endswith("-linux"):
7676
result["sys_platform"] = "linux"
77-
elif platform.endswith("-windows") or platform.endswith("-windows64"):
77+
elif platform.endswith(("-windows", "-windows64")):
7878
result["sys_platform"] = "win32"
7979
else:
8080
msg = f"Non supported platform {platform}"

src/e3/python/pypiscript.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def main() -> None:
207207
pypi.add_wheel(wheel.path)
208208

209209
for req in toplevel_reqs:
210-
logger.info(f"Add top-level requirement {str(req)}")
210+
logger.info(f"Add top-level requirement {req!s}")
211211
pypi.add_requirement(req)
212212

213213
packages: set[str] = set()
@@ -232,4 +232,4 @@ def main() -> None:
232232
if "discard_from_closure" not in config or not re.search(
233233
config["discard_from_closure"], req.name
234234
):
235-
fd.write(f"{str(req)}\n")
235+
fd.write(f"{req!s}\n")

tests/tests_e3/archive/main_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import e3.os.fs
1717

1818

19-
@pytest.mark.parametrize("ext", (".tar.gz", ".tar.bz2", ".tar.xz", ".tar", ".zip"))
19+
@pytest.mark.parametrize("ext", [".tar.gz", ".tar.bz2", ".tar.xz", ".tar", ".zip"])
2020
def test_unpack(ext: str) -> None:
2121
"""Test unpack."""
2222
dir_to_pack = str(Path(__file__).parent)
@@ -86,7 +86,7 @@ def test_unpack(ext: str) -> None:
8686
e3.fs.rm(dest, recursive=True)
8787

8888

89-
@pytest.mark.parametrize("ext", (".tar.gz", ".zip"))
89+
@pytest.mark.parametrize("ext", [".tar.gz", ".zip"])
9090
def test_unpack_fileobj(ext: str) -> None:
9191
"""Test unpack fileobj."""
9292
dir_to_pack = str(Path(__file__).parent)

0 commit comments

Comments
 (0)