DOI-USGS / DOI-USGS/dataretrieval-python

streamstats: should get_watershed always return a Watershed?

Aperta
#260 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
265
Fork
63
Merge medio
1g 20h
PR unite (30g)
19

Descrizione

## Background

`dataretrieval.streamstats.get_watershed` currently has a `format` parameter that selects between three return types:

- `format="geojson"` (default): the raw `requests.Response`
- `format="object"`: the parsed JSON `dict`
- `format="watershed"`: a `Watershed` instance built from the parsed JSON
- anything else: `ValueError`

The multi-return contract is documented in #245 (after that PR's fix). But the function's name and StreamStats' own conceptual model both suggest it should return a *watershed*.

## Proposal

Drop the `format` parameter and have `get_watershed` always return a `Watershed`.

Pros:
- Single return type → cleaner type annotation (`-> Watershed`), no `Union[Response, dict, Watershed]`.
- Function name matches its contract.
- Removes the silent-fallthrough bug class entirely (no `format` string to typo).
- Callers wanting the raw `Response` can use `requests.get(...)`; callers wanting JSON can call `Watershed.from_streamstats_json(r.json())` or read `Watershed.parameters` / `Watershed.workspace_id` directly.

Cons:
- **Breaking change** for callers using `format="geojson"` (the current default) or `format="object"`.
- The default behavior changes silently if a caller passed no `format` — they previously got a `Response` and would now get a `Watershed`.

## Implementation sketch

Extract the HTTP+parse into a private helper (`_fetch_streamstats_json`) so `get_watershed` and `Watershed.__init__` can share fetch logic without circular calls. A working draft of this lived briefly on the `fix/streamstats-watershed-class` branch (commit `b3a5d29`, since reverted to keep #245 non-breaking).

## Decision needed

Is this worth the breaking change? If so, when — current minor cycle, next major, or behind a deprecation warning?

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Leggi prima dataretrieval.streamstats.get_watershed e Watershed.__init__, quindi esamina la bozza del fix revocato fix/streamstats-watershed-class al commit b3a5d29. Esamina le implicazioni della breaking change per i formati documentati e determina se il progetto debba adottare la proposta, rimandarla a una major release o usare una deprecation; l'attività è completata quando la decisione e il relativo piano di compatibilità sono stati registrati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
api, backend
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.