Repository navigation
Commit 46ad5a3
authored
feat(types): support Python 3.14 in versioned model construction (#1379)
`versioned.py` built its annotation unions by calling
`Union.__getitem__(tuple(...))`. Python 3.14 makes that a descriptor
requiring a `typing.Union` instance, so handing it a tuple raises:
TypeError: descriptor '__getitem__' requires a 'typing.Union' object
but received a 'tuple'
`make_versioned_base` and the two annotation-union helpers all called it
that way, so every versioned model fails to build on 3.14. The SDK's
classifiers stop at 3.13 and CI covers 3.10-3.13, so this adds a version
rather than repairing a supported one.
Build the unions with the `|` operator instead, which is the spelling the
project's own lint rules ask for and is equivalent on every supported
version: `functools.reduce(operator.or_, ...)` where the arms come from a
variable-length sequence, and `annotation | None` for the one site that
only ever added `NoneType`. `|` applies the same dedup, nested-union
flattening and `Optional` collapsing as `Union[...]`, so the constructed
annotations are unchanged — verified equal across class, `Any`,
`types.GenericAlias`, `Literal`, `NoneType` and pre-unioned inputs.
`typing.Union` is no longer referenced and leaves the imports.
Clears 10 of the 12 tests that fail on 3.14 and pass on 3.12: all eight
in tests/test_version_scoped_models.py and both
tests/test_account_reference_request_fields.py::test_versioned_*.1 parent a083a19 commit 46ad5a3
1 file changed
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
20 | 21 | | |
21 | | - | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
175 | 176 | | |
176 | 177 | | |
177 | 178 | | |
178 | | - | |
| 179 | + | |
179 | 180 | | |
180 | 181 | | |
181 | 182 | | |
| |||
191 | 192 | | |
192 | 193 | | |
193 | 194 | | |
194 | | - | |
| 195 | + | |
195 | 196 | | |
196 | 197 | | |
197 | 198 | | |
| |||
483 | 484 | | |
484 | 485 | | |
485 | 486 | | |
486 | | - | |
| 487 | + | |
487 | 488 | | |
488 | 489 | | |
489 | 490 | | |
| |||
0 commit comments