Added additional Ruff rule sets and fixed all violations.
CI / Formatting (push) Successful in 11s
CI / Linting (push) Successful in 13s
CI / Tests (Python 3.12) (push) Successful in 25s
CI / Tests (Python 3.13) (push) Successful in 25s
CI / Tests (Python 3.14) (push) Successful in 24s
CI / Type Checking (push) Successful in 25s

This commit is contained in:
2026-02-19 14:15:08 -05:00
parent ca4adbcebf
commit 12c0394cf9
10 changed files with 118 additions and 88 deletions
+2 -2
View File
@@ -324,7 +324,7 @@ class Config:
logger.debug(f"Loading configuration from: {self.config_path.absolute()}")
if self.config_path.exists():
try:
with open(self.config_path) as f:
with self.config_path.open() as f:
self._data = yaml.safe_load(f) or {}
except yaml.YAMLError as e:
logger.error(f"Failed to parse config file: {e}")
@@ -385,7 +385,7 @@ class Config:
"""Write current configuration to the YAML file."""
logger.debug(f"Saving configuration to: {self.config_path.absolute()}")
try:
with open(self.config_path, "w") as f:
with self.config_path.open("w") as f:
yaml.safe_dump(
self._ordered_data(), f, default_flow_style=False, sort_keys=False
)
@@ -273,7 +273,9 @@ def _parse_placeholder_date(date_str: str) -> datetime | None:
return None
try:
dt = datetime.strptime(date_part, "%b %d %Y %I:%M:%S %p")
# Intentionally naive: tz abbreviation is resolved separately via
# TIMEZONE_OFFSETS since strptime's %z only handles numeric offsets.
dt = datetime.strptime(date_part, "%b %d %Y %I:%M:%S %p") # noqa: DTZ007
except ValueError:
return None
@@ -369,19 +371,17 @@ async def _evaluate_count(
(counter_name, delta, delta),
)
return str(result)
else:
try:
value = int(modifier_str)
except ValueError as e:
raise PlaceholderError(
"Invalid $(count): modifier must be an integer (e.g., +5, -1, 0)"
) from e
result = await ctx.storage.fetch_value(
"INSERT OR REPLACE INTO counters (name, value) VALUES (?, ?) "
"RETURNING value",
(counter_name, value),
)
return str(result)
try:
value = int(modifier_str)
except ValueError as e:
raise PlaceholderError(
"Invalid $(count): modifier must be an integer (e.g., +5, -1, 0)"
) from e
result = await ctx.storage.fetch_value(
"INSERT OR REPLACE INTO counters (name, value) VALUES (?, ?) RETURNING value",
(counter_name, value),
)
return str(result)
async def _evaluate_getcount(
@@ -429,7 +429,7 @@ async def _evaluate_rand(
raise PlaceholderError(
"Invalid $(rand): arguments must be integers, e.g., $(rand 1 100)"
) from e
return str(random.randint(min(start, stop), max(start, stop)))
return str(random.randint(min(start, stop), max(start, stop))) # noqa: S311
async def _evaluate_countdown(
@@ -455,8 +455,7 @@ async def _evaluate_countdown(
seconds = int(delta.total_seconds())
if seconds > 0:
return _format_duration(seconds)
else:
return "0 seconds"
return "0 seconds"
type PlaceholderHandler = Callable[
@@ -186,10 +186,9 @@ def _parse_placeholder(
)
if found_close:
return PlaceholderNode(name, child_nodes), new_pos
else:
# Unclosed placeholder, degrade to literal. Return None so
# the caller emits "$(" as literal and re-scans the rest.
return None
# Unclosed placeholder, degrade to literal. Return None so
# the caller emits "$(" as literal and re-scans the rest.
return None
# The character after the name is something unexpected (e.g. another $).
# Treat as unclosed/invalid -- degrade.
+8 -8
View File
@@ -401,16 +401,16 @@ class RouteDispatcher:
if result is None:
return web.Response(status=204) # No Content.
elif isinstance(result, web.StreamResponse):
if isinstance(result, web.StreamResponse):
return result
elif isinstance(result, dict):
if isinstance(result, dict):
return web.json_response(result)
else: # pragma: no branch — defensive against untyped handlers
mod_logger.error( # type: ignore[unreachable]
f"Route handler '{route_info.full_path}' returned "
f"unsupported type: {type(result).__name__}"
)
return web.Response(status=500)
# pragma: no branch — defensive against untyped handlers
mod_logger.error( # type: ignore[unreachable]
f"Route handler '{route_info.full_path}' returned "
f"unsupported type: {type(result).__name__}"
)
return web.Response(status=500)
except TimeoutError:
await module_ctx.storage._rollback()