aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorprabinpanta0 <pantaprabin30@gmail.com>2025-10-26 19:42:36 +0545
committerprabinpanta0 <pantaprabin30@gmail.com>2025-10-26 19:42:36 +0545
commit30839413484f72343d66035bbd77af700059d0a3 (patch)
tree5e6397879b89f5177f3266b7c244cd00ebc3bcc3 /config
parent7a147c0da9fb515cdb751014b737a33701063a74 (diff)
config(hypr): improve numeric coercion and add ensure_* warnings
- Parse numeric strings more robustly in coerce_number: convert to float then return int when the float has no fractional part (handles scientific notation and avoids brittle '.'/'e' checks). - Add diagnostic warnings to ensure_dict and ensure_list that print the unexpected type and a truncated repr to stderr to help detect API shape mismatches.
Diffstat (limited to 'config')
-rwxr-xr-xconfig/hypr/UserScripts/Weather.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/config/hypr/UserScripts/Weather.py b/config/hypr/UserScripts/Weather.py
index d76fb8db..a566d5ec 100755
--- a/config/hypr/UserScripts/Weather.py
+++ b/config/hypr/UserScripts/Weather.py
@@ -207,9 +207,9 @@ def coerce_number(value: Any) -> Union[int, float, None]:
return value
if isinstance(value, str):
try:
- # Try float first, then int if no decimal
+ # Parse to float, then return int if it has no fractional part
f = float(value)
- return f if '.' in value or 'e' in value.lower() else int(f)
+ return int(f) if f.is_integer() else f
except (ValueError, TypeError):
return None
return None
@@ -508,6 +508,11 @@ def ensure_dict(value: Any) -> JSONDict:
"""Return a JSON-like dict when the incoming value looks like one."""
if isinstance(value, dict):
return cast(JSONDict, value)
+ # Warn about unexpected type to catch API shape mismatches
+ val_repr = repr(value) if value is not None else "None"
+ if len(val_repr) > 100:
+ val_repr = val_repr[:100] + "..."
+ print(f"Warning: ensure_dict received {type(value).__name__} instead of dict: {val_repr}", file=sys.stderr)
return cast(JSONDict, {})
@@ -515,6 +520,11 @@ def ensure_list(value: Any) -> JSONList:
"""Return a JSON-like list when the incoming value looks like one."""
if isinstance(value, list):
return cast(JSONList, value)
+ # Warn about unexpected type to catch API shape mismatches
+ val_repr = repr(value) if value is not None else "None"
+ if len(val_repr) > 100:
+ val_repr = val_repr[:100] + "..."
+ print(f"Warning: ensure_list received {type(value).__name__} instead of list: {val_repr}", file=sys.stderr)
return cast(JSONList, [])
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage