refactor: extract _evaluated.py, _uri.py, rename _legacy_keywords to _keywords_draft3#1498
Closed
Wolfvin wants to merge 2 commits into
Closed
refactor: extract _evaluated.py, _uri.py, rename _legacy_keywords to _keywords_draft3#1498Wolfvin wants to merge 2 commits into
Wolfvin wants to merge 2 commits into
Conversation
…_keywords_draft3 Structural refactoring of jsonschema core modules for improved single-responsibility and cohesion: 1. DECOMPOSITION: Extract find_evaluated_item_indexes_by_schema and find_evaluated_property_keys_by_schema from _utils.py into new _evaluated.py module. These functions handle unevaluated* keyword tracking and are a distinct concern from general utilities. _utils.py reduced from 411 to 238 lines (42% reduction). 2. COHESION: Extract URIDict from _utils.py into _uri.py module. URI normalization is a distinct concern from JSON equality or uniqueness checking. 3. NAMING: Rename _legacy_keywords.py to _keywords_draft3.py for clarity. The old name was vague - 'legacy' could mean anything. The new name clearly identifies these as draft-3 specific keyword implementations. 4. SINGLE RESPONSIBILITY: is_valid() helper moved to _evaluated.py since it's closely related to evaluated item/property tracking. All changes are backward compatible via re-exports from _utils.py. Existing code that imports from _utils.py will continue to work without modification. Refactoring verified with output-based regression testing: - All existing test suites pass - All output values identical before and after refactoring - Fingerprint verification: all clusters match pre-refactor baselines
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.
What This Refactoring Does
This PR performs structural cleanup of the
jsonschemacore modules to improve single-responsibility, cohesion, and naming clarity.Changes
1. DECOMPOSITION — Extract _evaluated.py
find_evaluated_item_indexes_by_schema()andfind_evaluated_property_keys_by_schema()were extracted from_utils.pyinto a new_evaluated.pymodule. These functions handleunevaluated*keyword tracking and are a distinct concern from general utilities._utils.pyreduced from 411 to 238 lines (42% reduction)_evaluated.pymodule has single responsibility: evaluated item/property tracking2. COHESION — Extract _uri.py
URIDictwas extracted from_utils.pyinto_uri.py. URI normalization is a distinct concern from JSON equality or uniqueness checking.3. NAMING — Rename _legacy_keywords.py to _keywords_draft3.py
The old name
_legacy_keywordswas vague — "legacy" could mean anything. The new name_keywords_draft3clearly identifies these as draft-3 specific keyword implementations.4. SINGLE RESPONSIBILITY — Move is_valid()
The
is_valid()helper was moved to_evaluated.pysince it is closely related to evaluated item/property tracking.Backward Compatibility
All changes are backward compatible via re-exports from
_utils.py:from jsonschema._utils import URIDictstill worksfrom jsonschema._utils import find_evaluated_item_indexes_by_schemastill worksfrom jsonschema._utils import is_validstill worksExisting code that imports from
_utils.pywill continue to work without modification.Verification
This refactoring was verified using output-based regression testing (Regrets framework):
Fingerprints before refactoring:
Fingerprints after refactoring: IDENTICAL — all 11 clusters produce the same fingerprint.
Chain hashes: