Skip to content

Commit fb3de95

Browse files
mikejhillCopilot
andcommitted
fix: correct Python 2 except syntax across API modules
Replace bare comma-separated except clauses (Python 2 syntax) with parenthesized tuples (Python 3 syntax) in api.py, client.py, and parser.py. The comma syntax silently causes wrong behavior in Python 3 where only the first exception type is caught and the second is assigned as the exception variable. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0661953 commit fb3de95

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

custom_components/rouvy/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def _is_redirect_body(body: str) -> bool:
176176
data = json.loads(body)
177177
if isinstance(data, list) and len(data) > 0:
178178
return bool(data[0] == ["SingleFetchRedirect", 1])
179-
except ValueError, TypeError, IndexError:
179+
except (ValueError, TypeError, IndexError):
180180
pass
181181
return False
182182

custom_components/rouvy/api_client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def _is_redirect_response(self, response: requests.Response) -> bool:
286286
if isinstance(data, list) and len(data) > 0:
287287
return bool(data[0] == ["SingleFetchRedirect", 1])
288288
return False
289-
except ValueError, TypeError, IndexError:
289+
except (ValueError, TypeError, IndexError):
290290
return False
291291

292292

custom_components/rouvy/api_client/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def _decode_value(self, value: Any, resolve_int_as_index: bool = False) -> Any:
122122
if value[0] == "D" and isinstance(value[1], (int, float)):
123123
try:
124124
return datetime.fromtimestamp(value[1] / 1000)
125-
except ValueError, OSError:
125+
except (ValueError, OSError):
126126
_LOGGER.warning("Invalid timestamp: %s", value[1])
127127
return value
128128

@@ -350,7 +350,7 @@ def _safe_int(value: Any) -> int:
350350
return int(value)
351351
try:
352352
return int(value)
353-
except TypeError, ValueError:
353+
except (TypeError, ValueError):
354354
return 0
355355

356356

@@ -360,7 +360,7 @@ def _safe_float(value: Any) -> float:
360360
return float(value)
361361
try:
362362
return float(value)
363-
except TypeError, ValueError:
363+
except (TypeError, ValueError):
364364
return 0.0
365365

366366

0 commit comments

Comments
 (0)