Skip to content

Commit 86e3b7d

Browse files
committed
Use suppress insteady of try-except
1 parent 0550497 commit 86e3b7d

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

plugwise_usb/helpers/cache.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,27 +146,23 @@ async def write_cache(self, data: dict[str, str], rewrite: bool = False) -> None
146146
await temp_file.writelines(data_to_write)
147147
await temp_file.flush()
148148
# Ensure data reaches disk before rename
149-
try:
149+
with suppress(OSError, TypeError, AttributeError):
150+
# If fsync fails due to fileno() issues or other problems,
151+
# continue without it. Flush() provides reasonable durability.
150152
loop = get_running_loop()
151153
await loop.run_in_executor(None, os_fsync, temp_file.fileno())
152-
except (OSError, TypeError, AttributeError):
153-
# If fsync fails due to fileno() issues or other problems,
154-
# continue without it. flush() provides reasonable durability.
155-
pass
156154

157155
# Atomic rename (overwrites atomically on all platforms)
158156
temp_path.replace(cache_file_path)
159157
temp_path = None # Successfully renamed
160158
if os_name != "nt":
161159
# Ensure directory entry is persisted on POSIX
162-
try:
160+
with suppress(OSError, PermissionError):
161+
# Directory fsync may fail on some filesystems
162+
# The atomic replace is still complete
163163
await loop.run_in_executor(
164164
None, _fsync_parent_dir, cache_file_path.parent
165165
)
166-
except (OSError, PermissionError):
167-
# Directory fsync may fail on some filesystems
168-
# The atomic rename is still complete
169-
pass
170166

171167
if not self._cache_file_exists:
172168
self._cache_file_exists = True

0 commit comments

Comments
 (0)