Skip to content

Commit f9d8ed8

Browse files
robingenzclaude
andauthored
feat!: pass a catalog value newer than the client through (#25)
Every catalog field of a returned model is typed `Literal[...] | str`. A value the API adds later now arrives as it is, where the whole call raised a `ValidationError` before. Method arguments keep their closed types. A release condition the client cannot read, such as one of a type newer than the client, arrives as the new `UnknownCondition`. It keeps its `type`, and its other fields are in `model_extra`. The `conditions` argument of `apps.channels.releases.create` takes only the five known models. One contract test answers every call with catalog values and condition types the client does not know. BREAKING CHANGE: a catalog field of a returned model is typed `Literal[...] | str`, and `Release.conditions` is a list of `ReleaseCondition | UnknownCondition`. Code checked with mypy or pyright needs a branch for an unknown value and for `UnknownCondition`, and must narrow a response value before it passes it to a method argument. See BREAKING.md. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 1c83437 commit f9d8ed8

7 files changed

Lines changed: 146 additions & 51 deletions

File tree

‎BREAKING.md‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,56 @@ This is a comprehensive list of the breaking changes introduced in the minor ver
44

55
## Versions
66

7+
- [Version 0.9.x](#version-09x)
78
- [Version 0.8.x](#version-08x)
89

10+
## Version 0.9.x
11+
12+
### Open Catalogs in Responses
13+
14+
Every catalog field of a returned model is typed `Literal[...] | str`, such as `App.framework` as `Framework | str`. A value newer than your client now arrives as it is. Before, the whole call raised a pydantic `ValidationError`. Method arguments keep their closed types.
15+
16+
Nothing changes at runtime for the values your client knows. Only code checked with mypy or pyright must change, in two cases.
17+
18+
Code that handles every value needs a branch for a value it does not know:
19+
20+
```diff
21+
match app.framework:
22+
case "capacitor" | "cordova":
23+
...
24+
case "expo" | "react_native":
25+
...
26+
- case _ as unreachable:
27+
- assert_never(unreachable)
28+
+ case _:
29+
+ ...
30+
```
31+
32+
A value from a response that goes into a method argument, or into anything typed with the closed alias, must be narrowed first. A `match` on the known values narrows it, and so does a `TypeGuard` function. `==` and `in` do not narrow it under mypy:
33+
34+
```diff
35+
- client.organizations.apps.create(framework=app.framework, ...)
36+
+ match app.framework:
37+
+ case "capacitor" | "cordova" | "expo" | "react_native":
38+
+ client.organizations.apps.create(framework=app.framework, ...)
39+
```
40+
41+
### Unknown Release Conditions
42+
43+
`Release.conditions` is typed as a list of `ReleaseCondition | UnknownCondition`. A condition your client cannot read, such as one of a type newer than your client, arrives as an `UnknownCondition`. It keeps its `type`. Its other fields are in `model_extra`, under the API's camelCase names. Before, the whole call raised a pydantic `ValidationError`.
44+
45+
Code checked with mypy or pyright that handles every condition model needs a branch for `UnknownCondition`. A check of `condition.type` no longer narrows the model, so use `isinstance` or a class pattern:
46+
47+
```diff
48+
match condition:
49+
case AttributeCondition():
50+
...
51+
+ case UnknownCondition():
52+
+ ...
53+
```
54+
55+
The `conditions` argument of `apps.channels.releases.create` takes only the five known models. When a release holds an `UnknownCondition`, stop and update the client before you pass its conditions on. Never leave the condition out, since that widens the audience.
56+
957
## Version 0.8.x
1058

1159
### Flat Signature Fields

‎CLAUDE.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@ Run `uv run ruff format .` before every commit; the format check, lint, type che
7373
- The body and the query are dicts whose keys are the API's camelCase names, written out, `{"isProtected": is_protected}`, so a name greps against `openapi.json`.
7474
- Every path goes through `resolve_path` with the snapshot's template verbatim, `resolve_path("/v1/apps/{appId}", appId=app_id)`.
7575
- A method returns a model or a list of models, as the API answers; a status-only answer returns `None` through `fetch_status`.
76-
- A model is a `HotCodePushModel` named after the API's entity, its fields the snapshot's properties in snake_case: required ones without a default, nullable ones `X | None`, a relation `X | None = None`; a date-time is a `datetime`, an enum a `Literal`, an alias in `models.py` when two types share it.
76+
- A model is a `HotCodePushModel` named after the API's entity, its fields the snapshot's properties in snake_case: required ones without a default, nullable ones `X | None`, a relation `X | None = None`; a date-time is a `datetime`, an enum the caller sends a `Literal`, an alias in `models.py` when two types share it.
77+
- An enum a model reads from a response is that `Literal` or alias with `| str`, as in `Framework | str`, so a value newer than the client passes through. The `type` of a release condition picks the model, so it stays a closed `Literal`, and a condition the client cannot read, such as one of a type newer than the client, is read as an `UnknownCondition`.
7778
- A query flag documented as `"true" | "false"` is a `bool`.
7879
- After a resource's `list` method, an annotation writes `builtins.list`, since the method shadows the builtin in the class body.
7980
- A method whose operation the document marks with `sessionAuth` carries ``An API token answers `forbidden`; sign in with a session.`` in its docstring; the contract test holds the note to the document.
8081

8182
## The OpenAPI snapshot
8283

8384
The API's `/openapi` document is the contract, and `openapi.json` is its committed snapshot, the same bytes as `hotcodepush-node`'s, so the package builds and CI checks without the API.
84-
A schema change breaks `tests/test_openapi.py`, which calls every resource method once with every option it can send and answers it with the example of its operation's documented response: it fails when a method sends a path, method, query parameter, body field or content type the snapshot lacks, when it sends an `Idempotency-Key` where the operation documents none or none where it does, when a response property lands in a model's `model_extra` or fails its validation, when the session note and `sessionAuth` disagree, when a resource method has no call in `CALLS`, and when an operation has no method.
85+
A schema change breaks `tests/test_openapi.py`, which calls every resource method once with every option it can send and answers it with the example of its operation's documented response: it fails when a method sends a path, method, query parameter, body field or content type the snapshot lacks, when it sends an `Idempotency-Key` where the operation documents none or none where it does, when a response property lands in a model's `model_extra` or fails its validation, when a model refuses a catalog value newer than the client, when the session note and `sessionAuth` disagree, when a resource method has no call in `CALLS`, and when an operation has no method.
8586

8687
When the API changes:
8788

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Every method takes keyword arguments and returns pydantic models with snake_case
3434
Uploads take `bytes` or a file object with its `content_length` and stream it.
3535
Creating calls send an `Idempotency-Key` and are retried. Pass `idempotency_key` to reuse one across your own retries.
3636
A failed request raises a `HotCodePushError` with the API's `code`, `message`, `details` and the HTTP `status`. `code` is a `str`, so a code newer than your client passes through, and `ErrorCode` lists the codes this version knows.
37+
A catalog field of a model, such as `App.framework`, is typed `Framework | str` for the same reason.
38+
A release condition your client cannot read, such as one of a type newer than your client, is an `UnknownCondition`.
3739

3840
## Documentation
3941

‎src/hotcodepush/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
TelemetryExport,
8686
TelemetrySignal,
8787
TimeToAdoption,
88+
UnknownCondition,
8889
UpdateStatistics,
8990
UploadedBundlePack,
9091
UploadedPart,
@@ -184,6 +185,7 @@
184185
"TelemetryExport",
185186
"TelemetrySignal",
186187
"TimeToAdoption",
188+
"UnknownCondition",
187189
"UpdateStatistics",
188190
"UploadBody",
189191
"UploadedBundlePack",

0 commit comments

Comments
 (0)