refactor: move Cooldown class from context to candidate module#1114
refactor: move Cooldown class from context to candidate module#1114LalatenduMohanty merged 1 commit intopython-wheel-build:mainfrom
Conversation
Cooldown is a data class closely related to candidate filtering, not to the WorkContext lifecycle. Moving it to fromager.candidate removes a circular import workaround in resolver.py and keeps the candidate module self-contained. Co-Authored-By: Claude <claude@anthropic.com>
📝 WalkthroughWalkthroughThis pull request moves the Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/test_cooldown.py (1)
116-116:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winLocal variable
candidateshadows the importedcandidatemodule.Five test functions assign a local variable named
candidate, which shadowsfrom fromager import candidatefor the rest of that scope. No test currently usescandidate.Cooldownafter the shadowing, so there's no immediate bug — but any future edit that tries to do so inside one of these functions will getAttributeError: 'Candidate' object has no attribute 'Cooldown'.🛠️ Suggested fix — rename local variables
- candidate = result.mapping["test-pkg"] - assert str(candidate.version) == "1.3.2" + resolved = result.mapping["test-pkg"] + assert str(resolved.version) == "1.3.2"Apply the same rename (
resolvedorc) in the other affected lines (137, 166, 535, 604).Also applies to: 137-137, 166-166, 535-535, 604-604
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_cooldown.py` at line 116, A local variable named "candidate" is shadowing the imported module "candidate" (from fromager), so rename the local variable instances (e.g., the assignment "candidate = result.mapping['test-pkg']" and the other similar assignments) to a non-conflicting name like "resolved" or "c" and update any subsequent uses in those test functions; ensure any references to the module's symbol candidate.Cooldown still refer to the imported module rather than the local variable.
🧹 Nitpick comments (1)
src/fromager/candidate.py (1)
18-29: ⚡ Quick winConsider adding
frozen=TruetoCooldownto match the docstring's immutability guarantee.The docstring says
bootstrap_timeis "fixed at construction", but the dataclass allows post-construction mutation.Candidatein the same file isfrozen=True;Cooldownshould follow suit. No current callers mutate fields after creation, so the change is safe.♻️ Proposed refactor
-@dataclasses.dataclass +@dataclasses.dataclass(frozen=True) class Cooldown:🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/fromager/candidate.py` around lines 18 - 29, The Cooldown dataclass is mutable but the docstring states bootstrap_time is fixed; make it immutable by adding frozen=True to the `@dataclasses.dataclass` decorator for class Cooldown so its fields (including bootstrap_time) cannot be modified after construction; locate the Cooldown class definition and change `@dataclasses.dataclass` to `@dataclasses.dataclass`(frozen=True) (mirroring Candidate) to enforce immutability.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@tests/test_cooldown.py`:
- Line 116: A local variable named "candidate" is shadowing the imported module
"candidate" (from fromager), so rename the local variable instances (e.g., the
assignment "candidate = result.mapping['test-pkg']" and the other similar
assignments) to a non-conflicting name like "resolved" or "c" and update any
subsequent uses in those test functions; ensure any references to the module's
symbol candidate.Cooldown still refer to the imported module rather than the
local variable.
---
Nitpick comments:
In `@src/fromager/candidate.py`:
- Around line 18-29: The Cooldown dataclass is mutable but the docstring states
bootstrap_time is fixed; make it immutable by adding frozen=True to the
`@dataclasses.dataclass` decorator for class Cooldown so its fields (including
bootstrap_time) cannot be modified after construction; locate the Cooldown class
definition and change `@dataclasses.dataclass` to
`@dataclasses.dataclass`(frozen=True) (mirroring Candidate) to enforce
immutability.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 63fee026-f4a3-4e72-b366-3793ab9f70b4
📒 Files selected for processing (6)
src/fromager/__main__.pysrc/fromager/candidate.pysrc/fromager/context.pysrc/fromager/packagesettings/_pbi.pysrc/fromager/resolver.pytests/test_cooldown.py
1429c1a
into
python-wheel-build:main
Pull Request Description
What
Cooldown is a data class closely related to candidate filtering, not to the WorkContext lifecycle.
Why
Moving it to fromager.candidate removes a circular import workaround in resolver.py and keeps the candidate module self-contained.