Repository navigation
Commit b1d4132
authored
fix(zarr-metadata): make JSONValue's array arm covariant (#4264)
* fix(zarr-metadata): make JSONValue's array arm covariant
`list["JSONValue"] | tuple["JSONValue", ...]` is invariant in the element
type, so a value typed with any narrower element -- a `list[str]` field on
a TypedDict, a `Sequence[float]` -- was not assignable to `JSONValue`, and
a TypedDict carrying such fields was not assignable to
`Mapping[str, JSONValue]`. pyright's diagnostic for the failure suggests
the fix verbatim: "Consider switching from list to Sequence which is
covariant."
The array arm is now `Sequence["JSONValue"]`. The docstring records the
deliberate type-level cost (`Sequence` admits `str`/`bytes`; runtime
narrowing must exclude them regardless of the alias's spelling).
Found while aliasing zarr-cm's JsonValue to this type: the two aliases
are structurally identical except for this arm, and with it changed,
pyright unifies them across the package boundary.
Assisted-by: ClaudeCode:claude-opus-5
* Rename 295.bugfix.md to 4264.bugfix.md1 parent 12aa83b commit b1d4132
2 files changed
Lines changed: 24 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 16 | + | |
24 | 17 | | |
25 | 18 | | |
26 | 19 | | |
27 | 20 | | |
28 | 21 | | |
29 | 22 | | |
30 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
31 | 37 | | |
32 | 38 | | |
33 | 39 | | |
| |||
0 commit comments