fix: code quality and type safety improvements#815
Open
caverac wants to merge 1 commit intojobovy:mainfrom
Open
fix: code quality and type safety improvements#815caverac wants to merge 1 commit intojobovy:mainfrom
caverac wants to merge 1 commit intojobovy:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #815 +/- ##
==========================================
- Coverage 99.91% 99.84% -0.08%
==========================================
Files 213 213
Lines 30740 30781 +41
Branches 627 627
==========================================
+ Hits 30713 30732 +19
- Misses 27 49 +22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
This PR
1. Python Improvements
Bare Except Clauses Replaced with Specific Exceptions
Standard: PEP 8 - Programming Recommendations
Bare
except:clauses catch all exceptions which can mask bugs, prevent proper exception handling, hide errors and make debugging difficult.Comparison Operator Style Fixed
Standard: PEP 8 - Programming Recommendations
The negation pattern
not x is yis less readable thanx is not y. PEP 8 explicitly recommends using the latter form for clarity.Import Aliases Standardized
Standard: PEP 8 - Imports and community conventions
For maximum clarity in a scientific library, using the full
import numpywithnumpy.prefix was chosen to be explicit.Unnecessary
return NoneRemovedStandard: PEP 8 - Programming Recommendations
For functions that don't return a value (procedures), Python implicitly returns
None.Pythonic Iteration Patterns
Standard: PEP 20 - The Zen of Python
The
range(len(x))pattern is a common anti-pattern in Python. Usingenumerate()for index-value pairs andzip()for parallel iteration is more Pythonic, readable, and less error-prone.2. Typing Improvements
PEP 561 Type Checker Support
Standard: PEP 561 - Distributing and Packaging Type Information
Added
py.typedmarker file to indicate that the package supports type checking. This allows type checkers likemypy,pyright, and IDEs to recognize that galpy provides type information.Type Annotations
Standards:
Added type hints to core module functions and methods. Type hints provide:
3. Refactor
ConversionContext Class for DRY Parameter Handling
Principles:
Created a
ConversionContextclass to address the repetitive(vo, ro)parameter passing across 15+ conversion functions. This follows the DRY principle by allowing users to set conversion parameters once and reuse them.Problem: Every conversion function required passing the same
voandroparameters:Solution: Context object stores parameters once:
This refactor:
ro/voaccidentally)