refactor(wqp): collapse the 8 what_* bodies into a shared _what helper#320
Merged
Merged
Conversation
The what_sites/what_organizations/what_projects/what_activities/ what_detection_limits/what_habitat_metrics/what_project_weights/ what_activity_metrics functions had byte-identical bodies differing only by the service name and which URL builder they used. Factor the shared body (kwarg check -> URL resolution -> query -> CSV parse -> metadata) into a private _what() helper; each public function becomes a one-line delegator. The WQX3.0-capable services are derived from the existing services_wqx3 constant (single source of truth) rather than hardcoded per function. Public signatures, docstrings, and observable behavior are unchanged. _warn_wqx3_unavailable's stacklevel is bumped 3 -> 4 to account for the extra _what frame so the warning is still attributed to the public what_* call site. Net -26 LOC; no behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
The eight
what_*metadata-search functions indataretrieval/wqp.py(
what_sites,what_organizations,what_projects,what_activities,what_detection_limits,what_habitat_metrics,what_project_weights,what_activity_metrics) had byte-identical bodies differing only by theservice name string and which URL builder they used. This factors that shared
body into one private
_what()helper; each public function becomes a one-linedelegator.
The WQX3.0-capable services (
Station,Activity) are derived from theexisting
services_wqx3constant rather than hardcoded per function, so thelist of WQX3-capable services lives in exactly one place.
Why
Pure structural duplication: ~9 identical lines × 8 functions. Consolidating
removes the copy-paste and makes future changes to the request/parse flow a
one-line edit instead of an eight-place edit.
Scope / non-goals
what_*keeps its name, parameters,and full docstring (these render into the Sphinx API reference).
_whatcall frame shifts_warn_wqx3_unavailable'sstacklevelby one, soit's bumped
3 → 4to keep attributing the "WQX3.0 profile not available"warning to the public
what_*call site./ Returns blocks) is intentionally left out of this PR since it touches
rendered public docs — happy to do it as a follow-up if wanted.
Net
dataretrieval/wqp.py: +48 / −74 (−26 LOC).Verification
ruff format+ruff check(preview rules): cleanmypy --strict: cleanpytest tests/wqp_test.py: 15 passed (allwhat_*covered)pytest tests/nwis_test.py tests/utils_test.py: 77 passed (NWIS_Metadata.site_info→wqp.what_sitespath exercised)🤖 Generated with Claude Code