fix: replace mutable default set with None in wait_for_job_status#330
fix: replace mutable default set with None in wait_for_job_status#330Roaimkhan wants to merge 2 commits intokubeflow:mainfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Pull request overview
This PR fixes a Python anti-pattern where mutable set literals were used as default arguments in wait_for_job_status methods across trainer and optimizer backends. Using mutable defaults can cause all callers to share the same object, leading to subtle bugs if that object is ever mutated. The fix follows the canonical Python pattern: replace the mutable default with None and assign the real default value inside the function body.
Changes:
- Updated all
wait_for_job_statusmethod signatures to usestatus: set[str] | None = Noneinstead ofstatus: set[str] = {constants.CONSTANT} - Added
if status is None:checks at the beginning of each method to assign the default value - Updated docstring in
trainer_client.pyto document the default value
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| kubeflow/trainer/backends/localprocess/backend.py | Fixed mutable default in wait_for_job_status |
| kubeflow/trainer/backends/kubernetes/backend.py | Fixed mutable default in wait_for_job_status |
| kubeflow/trainer/backends/container/backend.py | Fixed mutable default in wait_for_job_status |
| kubeflow/trainer/backends/base.py | Fixed mutable default in abstract base method |
| kubeflow/trainer/api/trainer_client.py | Fixed mutable default and updated docstring |
| kubeflow/optimizer/backends/kubernetes/backend.py | Fixed mutable default in wait_for_job_status |
| kubeflow/optimizer/backends/base.py | Fixed mutable default in abstract base method |
| kubeflow/optimizer/api/optimizer_client.py | Fixed mutable default in wait_for_job_status |
Signed-off-by: Roaim <roimkhan459@gmail.com>
Signed-off-by: Roaim <roimkhan459@gmail.com>
d82c041 to
ca0982a
Compare
What this PR does / why we need it:
Python evaluates default argument values once at function definition time. Using a mutable set literal as a default means all callers share the same object — if it's ever mutated, every subsequent call using the default sees the corrupted state.
This PR fixes all instances of this pattern across the trainer and optimizer backends by replacing the mutable default with None and assigning the real value inside the function body, which is the canonical Python solution.
Before:
After:
Fixes #329
Checklist: