fix: replace mutable default arguments with None + in-body defaults - #1068
Conversation
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoFix mutable default args by defaulting to None in graph/chunker APIs
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
1.
|
…els in split_hierarchical Three findings from the Qodo review: - analyze_temporal_evolution: the 'if metrics is None' block had landed inside the docstring, so it never executed and metrics_tracked came back None. Moved below the docstring where it runs. - HierarchicalChunker.__init__: the same misplacement turned the docstring into a dead string constant and broke help()/introspection. Moved the default-init below it. - split_hierarchical: the signature now defaults levels to None, but the body still ran 'in levels' membership tests — calling it without levels raised TypeError. Defaults to the documented hierarchy, matching the class-level default.
|
All three Qodo findings addressed and pushed:
|
ZohaibHassan16
left a comment
There was a problem hiding this comment.
Looks good to me. The default values are preserved and the previous review points have been addressed.
Approved.
- tests/split/test_chunkers.py: TestMutableDefaultRegression (6 tests) - split_hierarchical() default levels and chunk_sizes stay independent across calls - HierarchicalChunker() default levels stay independent across instances - tests/kg/test_kg.py: TestAnalyzeTemporalEvolutionMutableDefault (5 tests) - analyze_temporal_evolution() default metrics value is canonical - mutations to a returned metrics_tracked list do not affect the next call - explicit metrics override is forwarded and reflected in the return value - mutating an explicitly passed list does not corrupt a subsequent default call All 96 tests in the two affected test files pass.
Sameer6305
left a comment
There was a problem hiding this comment.
Review — Approved ✅
At the start of the review, this PR addressed three mutable list defaults in function signatures:
GraphAnalyzer.analyze_temporal_evolution(metrics=[...])
HierarchicalChunker.init(levels=[...])
split_hierarchical(levels=[...])
The original fix correctly replaces these shared mutable defaults with None and creates the default lists inside the function body. This prevents state/mutations from leaking between calls while preserving the existing default behavior.
During review, we also added focused regression coverage for all three affected sites. The tests specifically verify that:
default lists are independent between calls/instances,
the expected default values are preserved,
explicit values continue to work correctly,
mutations do not affect subsequent calls.
The affected test suites pass 96/96, and the reviewed changes contain no unrelated modifications.
The additional regression tests strengthen the PR by ensuring this mutable-default bug cannot silently return in the future.
Conclusion: The implementation is correct, the scope is appropriate, and regression coverage is now in place. Approved for merge. ✅
Three mutable default arguments (list literals in function signatures) replaced with None + in-body assignment:
Mutable defaults persist across calls — any mutation inside the function leaks to subsequent calls with the same default. The None pattern creates a fresh list each time.