Repository navigation
fix(sorts): remove shadowed type parameter from bogo_sort is_sorted helper - #15605
hardikkaurani wants to merge 1 commit into
Conversation
…elper In PEP 695 syntax, T is already bound by the outer function bogo_sort[T: Comparable]. Re-declaring [T: Comparable] on the nested is_sorted helper shadows T and causes ty check to emit error[shadowed-type-variable]. Remove [T: Comparable] from is_sorted so it uses the enclosing type variable T, matching other sorting algorithms in sorts/ (e.g. circle_sort, merge_sort). Validation: - uvx ty check sorts/bogo_sort.py -> All checks passed - uvx pytest sorts/bogo_sort.py --doctest-modules -> 1 passed - uvx pytest tests/test_sorts.py -k test_bogo_sort -> 1 passed - uvx ruff check / format -> clean
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
Hi @cclauss, I've opened this small PR to resolve a shadowed type parameter in Overview:In Removing
Whenever you have a chance, could you please take a look? Thank you! |
Describe your change
Problem & Context
In
sorts/bogo_sort.py,bogo_sortis generic overT: Comparableusing PEP 695 syntax:Inside
bogo_sort, the nested helper functionis_sortedre-declared[T: Comparable]:Because
Tis already in scope from the enclosing function, this shadowsTand causesty checkto emit:Fix
Remove
[T: Comparable]fromis_sortedso it uses the enclosing type variableT, which matches how other nested helper functions are typed acrosssorts/(e.g.mergeinsorts/merge_sort.pyandcircle_sort_utilinsorts/circle_sort.py).Validation
uvx ty check sorts/bogo_sort.py-> All checks passed (0 diagnostics).uvx pytest sorts/bogo_sort.py --doctest-modules-> 1 passed.uvx pytest tests/test_sorts.py -k test_bogo_sort-> 1 passed.uvx ruff check sorts/bogo_sort.py-> All checks passed.uvx ruff format --check sorts/bogo_sort.py-> 1 file already formatted.Checklist