refactor: Pythonic cleanup of gematria.py and utils.py (regression-tested)#33
Open
Wolfvin wants to merge 1 commit into
Open
refactor: Pythonic cleanup of gematria.py and utils.py (regression-tested)#33Wolfvin wants to merge 1 commit into
Wolfvin wants to merge 1 commit into
Conversation
Behavior-preserving refactoring verified by Regrets 3-way regression testing. ## Changes to gematria.py - Added module-level docstring with clear purpose description - Extracted _SPECIAL_REPLACEMENTS dict for divine-name-avoidance rule (15→טו, 16→טז), replacing hidden .replace() calls - Extracted _apply_special_replacements() as a dedicated function - Named constants: _GERESH, _GERSHAYIM, _TAV for Unicode characters - Improved variable names in _get_letters(): ones→ones_digit, tens→tens_digit, hundreds→hundreds_raw, four_hundreds→tav_count/tav_prefix - Added comprehensive docstrings with parameter documentation - Simplified _stringify_gematria() with early return pattern ## Changes to utils.py - Simplified _is_leap() from if/return True/return False to direct boolean return, with docstring explaining the Metonic cycle - Extracted _apply_postponement() from _elapsed_days() with named dehiyyah rules: Molad Zakein, Gatarad, Betutakafot - Used frozenset for month membership testing in _month_length() (O(1) lookup instead of O(n) list scan) - Replaced nested if/return with Pythonic ternary expressions - Simplified _month_name() with ternary name list selection - Added comprehensive docstrings to all modified functions ## Verification 7 Regrets clusters fingerprinted and all passed 3-way verification: 1. Regrets clusters: all GREEN after refactoring 2. Raw output: identical to pre-refactor baseline 3. Fingerprint cross-check: all hashes match exactly Clusters: gematria-convert (69vpdvu), hebrew-leap (5wtkimf), month-length (fny25om), month-name (3pfo2au), elapsed-days (5hj9vhu), get-letters (2lcwua6), stringify-gematria (5etsuwj)
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.
Pythonic Cleanup — Verified Safe by Regression Testing
This PR contains behavior-preserving refactoring of
gematria.pyandutils.py, verified using Regrets — an output-fingerprint regression testing tool.Changes to
gematria.py_SPECIAL_REPLACEMENTSdict for the divine-name-avoidance rule (15→טו, 16→טז), replacing hidden.replace()calls chained together_apply_special_replacements()as a dedicated, self-documenting function_GERESH,_GERSHAYIM,_TAV— replacing inline Unicode characters that are hard to distinguish_get_letters():ones→ones_digit,tens→tens_digit,hundreds→hundreds_raw,four_hundreds→tav_count/tav_prefix_stringify_gematria()with early return for empty inputChanges to
utils.py_is_leap()from redundantif (condition): return True; return Falseto directreturn condition, with docstring explaining the 19-year Metonic cycle_apply_postponement()from_elapsed_days()— the three dehiyyah (postponement) rules (Molad Zakein, Gatarad, Betutakafot) are now in a separate, well-documented function with named boolean variables instead of a deeply nested conditionalfrozensetfor month membership testing in_month_length()(O(1) lookup instead of O(n) list scan)_month_name()with ternary name list selection3-Way Regression Test Verification
Using Regrets, I fingerprinted 7 behavioral clusters before refactoring, then verified after refactoring:
_num_to_str_is_leap_month_length_month_name_elapsed_days_get_letters_stringify_gematria3 verifications all passed:
No behavioral changes — only code clarity and maintainability improvements.