Skip to content

Commit 73160a2

Browse files
committed
pip: Replace try-except with contextlib.suppress()
Fixes SIM105
1 parent 5dbc739 commit 73160a2

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

pip/flatpak-pip-generator.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import urllib.request
1515
from collections import OrderedDict
1616
from collections.abc import Iterator
17+
from contextlib import suppress
1718
from typing import Any, TextIO
1819

1920
try:
@@ -342,10 +343,8 @@ def fprint(string: str) -> None:
342343
print("Ignore the error by passing --ignore-errors")
343344
raise
344345

345-
try:
346+
with suppress(FileNotFoundError):
346347
os.remove(requirements_file_output)
347-
except FileNotFoundError:
348-
pass
349348

350349
fprint("Downloading arch independent packages")
351350
for filename in os.listdir(tempdir):
@@ -361,10 +360,8 @@ def fprint(string: str) -> None:
361360
# available like for wasmtime-27.0.2
362361
unresolved_dependencies_errors.append(err)
363362
print("Deleting", filename)
364-
try:
363+
with suppress(FileNotFoundError):
365364
os.remove(os.path.join(tempdir, filename))
366-
except FileNotFoundError:
367-
pass
368365

369366
files: dict[str, list[str]] = {get_package_name(f): [] for f in os.listdir(tempdir)}
370367

@@ -382,10 +379,8 @@ def fprint(string: str) -> None:
382379
if zip_source:
383380
for f in files[name]:
384381
if not f.endswith(".zip"):
385-
try:
382+
with suppress(FileNotFoundError):
386383
os.remove(os.path.join(tempdir, f))
387-
except FileNotFoundError:
388-
pass
389384

390385
vcs_packages: dict[str, dict[str, str | None]] = {
391386
str(x.name): {"vcs": x.vcs, "revision": x.revision, "uri": x.uri}

0 commit comments

Comments
 (0)