Skip to content

Commit

Permalink
fix: fix B904 ruff rule (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Aug 6, 2024
1 parent ee089a1 commit 3367c3c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ ignore = [
"B008", # Do not perform function call
"S110", # `try`-`except`-`pass` detected, consider logging the exception
"D106", # Missing docstring in public nested class
"B904",
"UP007", # typer needs Optional syntax
"UP038", # Use `X | Y` in `isinstance` is slower
"S603", # check for execution of untrusted input
Expand Down
6 changes: 3 additions & 3 deletions src/uvcclient/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def _safe_request(self, *args, **kwargs):
conn = httplib.HTTPConnection(self._host, self._port)
conn.request(*args, **kwargs)
return conn.getresponse()
except OSError:
raise CameraConnectError("Unable to contact camera")
except OSError as ex:
raise CameraConnectError("Unable to contact camera") from ex
except httplib.HTTPException as ex:
raise CameraConnectError(f"Error connecting to camera: {ex!s}")
raise CameraConnectError(f"Error connecting to camera: {ex!s}") from ex

def login(self):
resp = self._safe_request("GET", "/")
Expand Down
16 changes: 8 additions & 8 deletions src/uvcclient/nvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,18 @@ def _safe_request(self, *args, **kwargs):
conn = self._get_http_connection()
conn.request(*args, **kwargs)
return conn.getresponse()
except OSError:
raise CameraConnectionError("Unable to contact camera")
except OSError as ex:
raise CameraConnectionError("Unable to contact camera") from ex
except httplib.HTTPException as ex:
raise CameraConnectionError(f"Error connecting to camera: {ex!s}")
raise CameraConnectionError(f"Error connecting to camera: {ex!s}") from ex

def _uvc_request(self, *args, **kwargs):
try:
return self._uvc_request_safe(*args, **kwargs)
except OSError:
raise NvrError("Failed to contact NVR")
except OSError as ex:
raise NvrError("Failed to contact NVR") from ex
except httplib.HTTPException as ex:
raise NvrError(f"Error connecting to camera: {ex!s}")
raise NvrError(f"Error connecting to camera: {ex!s}") from ex

def _uvc_request_safe(
self, path, method="GET", data=None, mimetype="application/json"
Expand Down Expand Up @@ -204,10 +204,10 @@ def set_picture_settings(self, uuid, settings):
dtype = type(data["data"][0]["ispSettings"][key])
try:
data["data"][0]["ispSettings"][key] = dtype(settings[key])
except ValueError:
except ValueError as ex:
raise Invalid(
f"Setting `{key}' requires {dtype.__name__} not {type(settings[key]).__name__}"
)
) from ex
data = self._uvc_request(url, "PUT", json.dumps(data["data"][0]))
return data["data"][0]["ispSettings"]

Expand Down
4 changes: 2 additions & 2 deletions src/uvcclient/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def load(self):
self._data = {}
except Exception as ex:
LOG.error("Failed to read store data: %s", ex)
raise UnableToManageStore("Unable to write to store")
raise UnableToManageStore("Unable to write to store") from ex

def save(self):
try:
Expand All @@ -36,7 +36,7 @@ def save(self):
os.chmod(self._path, 0o600)
except OSError as ex:
LOG.error("Unable to write store: %s", str(ex))
raise UnableToManageStore("Unable to write to store")
raise UnableToManageStore("Unable to write to store") from ex

def get_camera_passwords(self):
return self._data.get("camera_passwords", {})
Expand Down

0 comments on commit 3367c3c

Please sign in to comment.