Code review: fix 5 oldest code files with type hints and improvements#14564
Open
JiayangLai wants to merge 2 commits intoTheAlgorithms:masterfrom
Open
Code review: fix 5 oldest code files with type hints and improvements#14564JiayangLai wants to merge 2 commits intoTheAlgorithms:masterfrom
JiayangLai wants to merge 2 commits intoTheAlgorithms:masterfrom
Conversation
- searches/sentinel_linear_search.py: - Added type hints for function parameters and return type - Added Collection import - Fixed docstring formatting and improved examples - Fixed return check (index >= len(sequence) instead of index == len(sequence)) - Fixed grammar in print statement - sorts/pancake_sort.py: - Added type hints and return type annotation - Fixed list copying to avoid mutating input - Improved docstring with proper Args/Returns documentation - Fixed slicing syntax for clarity - graphs/g_topological_sort.py: - Refactored from global variables to proper class-based design - Added TopologicalSort class with type hints - Added proper docstrings and examples - Kept functional interface for backwards compatibility - Improved main block with both class and functional examples - dynamic_programming/abbreviation.py: - Added type hints and early exit checks - Fixed broken/malformed docstring - Added more comprehensive doctest examples - Added early exit for impossible cases - digital_image_processing/change_brightness.py: - Fixed typo: brigt_img -> bright_img - Added type hints - Fixed nested function docstring (wrong description about "bits") - Fixed pixel adjustment to use int() for proper clamping - Added CLI interface with proper argument handling - Made image paths configurable via command line Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses code quality issues in the 5 oldest Python files in the repository (by last commit date, not updated since 2020). Each file has been audited and fixed with modern Python best practices.
Changes Made
searches/sentinel_linear_search.py:
index >= len(sequence)instead ofindex == len(sequence))sorts/pancake_sort.py:
graphs/g_topological_sort.py:
TopologicalSortclass)dynamic_programming/abbreviation.py:
digital_image_processing/change_brightness.py:
brigt_img->bright_imgint()for proper clampingTest plan
python -m doctesttests🤖 Generated with Claude Code