Skip to content

Commit e06e792

Browse files
agnersclaude
andauthored
Fix type annotations for sentinel values in job manager (#6349)
Add `type[DEFAULT]` to type annotations for parameters that use the DEFAULT sentinel value. This fixes runtime type checking failures with typeguard when sentinel values are passed as arguments. Use explicit type casts and restructured parameter passing to satisfy mypy's type narrowing requirements. The sentinel pattern allows distinguishing between "parameter not provided" and "parameter explicitly set to None", which is critical for job management logic. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
1 parent 5f55ab8 commit e06e792

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

supervisor/jobs/__init__.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from dataclasses import dataclass
1010
from datetime import datetime
1111
import logging
12-
from typing import Any, Self
12+
from typing import Any, Self, cast
1313
from uuid import uuid4
1414

1515
from attr.validators import gt, lt
@@ -196,7 +196,7 @@ def update(
196196
self,
197197
progress: float | None = None,
198198
stage: str | None = None,
199-
extra: dict[str, Any] | None = DEFAULT, # type: ignore
199+
extra: dict[str, Any] | None | type[DEFAULT] = DEFAULT,
200200
done: bool | None = None,
201201
) -> None:
202202
"""Update multiple fields with one on change event."""
@@ -207,8 +207,8 @@ def update(
207207
self.progress = progress
208208
if stage is not None:
209209
self.stage = stage
210-
if extra != DEFAULT:
211-
self.extra = extra
210+
if extra is not DEFAULT:
211+
self.extra = cast(dict[str, Any] | None, extra)
212212

213213
# Done has special event. use that to trigger on change if included
214214
# If not then just use any other field to trigger
@@ -306,19 +306,21 @@ def new_job(
306306
reference: str | None = None,
307307
initial_stage: str | None = None,
308308
internal: bool = False,
309-
parent_id: str | None = DEFAULT, # type: ignore
309+
parent_id: str | None | type[DEFAULT] = DEFAULT,
310310
child_job_syncs: list[ChildJobSyncFilter] | None = None,
311311
) -> SupervisorJob:
312312
"""Create a new job."""
313-
job = SupervisorJob(
314-
name,
315-
reference=reference,
316-
stage=initial_stage,
317-
on_change=self._on_job_change,
318-
internal=internal,
319-
child_job_syncs=child_job_syncs,
320-
**({} if parent_id == DEFAULT else {"parent_id": parent_id}), # type: ignore
321-
)
313+
kwargs: dict[str, Any] = {
314+
"reference": reference,
315+
"stage": initial_stage,
316+
"on_change": self._on_job_change,
317+
"internal": internal,
318+
"child_job_syncs": child_job_syncs,
319+
}
320+
if parent_id is not DEFAULT:
321+
kwargs["parent_id"] = parent_id
322+
323+
job = SupervisorJob(name, **kwargs)
322324

323325
# Shouldn't happen but inability to find a parent for progress reporting
324326
# shouldn't raise and break the active job

0 commit comments

Comments
 (0)