Refactor OGC and fan-out internals - #381
Draft
thodson-usgs wants to merge 1 commit into
Draft
Conversation
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 applies exactly five metric-gated architecture refactors to the OGC and fan-out internals. All five were retained because each reduced meaningful local and package complexity, preserved behavior, kept every coarse PySCN score non-regressing, introduced no clone group, and kept all dependency contracts intact.
The work is based on
upstream/mainatc3242789and is independent of draft PR #353. It changes no public interface or import path.Recent PySCN history
I measured the last 15 first-parent commits with the same PySCN version and verified project-root resolution for every report.
702c6ad9) temporarily lowered health 81→80 and cohesion 100→95.3474c3cc) recovered health 80→82, cohesion 95→100, dependency score 75→80, and depth 9→8.0ff534c2) lowered architecture 87→82 without changing overall health; PR refactor(ratings): drive both stages through the shared executor #369 restored architecture to 87.ed307b7d) moved architecture 87→84, again without changing health.ced0d1ea) moved duplication 8.7%→9.5% and clone groups 5→6 while health remained 82.c3242789) made no PySCN change.The sixth clone group after #372 is Type-4 semantic similarity between
wqp.get_resultsandwqp._what. Those functions have distinct service behavior, so this PR intentionally does not collapse it. It likewise does not optimize intentional collection-family getter resemblance or treat Python leaf modules in a reported “zone of pain” as defects.Five measured iterations
FanOut._raise_failures_run: CC 11→4, cognitive 33→8, nesting 4→3; high-risk functions 21→20_advance_structure_split_top_level_or: CC 11→6, cognitive 15→8, nesting 7→3_format_date_params_construct_api_requests: CC 6→4, cognitive 7→3, nesting 2→1_normalize_request_argprepare_request_args: CC 8→4, cognitive 17→6, nesting 5→2_largest_splittable_chunkChunkPlan._refine: CC 10→5, cognitive 24→6, nesting 4→2No experiment was reverted: every candidate met the retain gate. Iteration 4 briefly moved duplication from 9.4737% to 9.5070% without adding a group; iteration 5 returned it to baseline.
Updated PySCN scores
Architecture-metrics corroborates the local trend: maintainability index improved in all five touched modules, max CC fell in
filters12→10,requests13→12, andfanout13→8, and every touched module retained identical afferent/efferent coupling.FanOutLCOM96b moved slightly 0.840→0.856 when failure precedence became a named method; this is treated as a holistic trend rather than outweighing the method's large local complexity reduction, stable PySCN cohesion, unchanged coupling, and clearer ADR-0008 policy seam.Architecture
ogc.dates.FanOutand preserves ADR 0008 behavior.An independent Standards/Spec review found no hard or spec findings. It noted one mild same-module Feature Envy judgment call for
_largest_splittable_chunk; no action was recommended because the selector is pure, private, and local to the planning module.Validation
pytest -q tests -k 'not test_nwis_service_live': 813 passed, 12 deselected, 57 expected warningsruff format --check .ruff check .mypy --strict dataretrieval: all 58 source files passedlint-imports: 7 kept, 0 brokengit diff --check