Skip to content

Commit d142672

Browse files
yzhkaliTinche
authored andcommitted
Document type alias union passthrough support
1 parent f693a0b commit d142672

4 files changed

Lines changed: 12 additions & 0 deletions

File tree

HISTORY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Our backwards-compatibility policy can be found [here](https://github.com/python
2626
([#732](https://github.com/python-attrs/cattrs/pull/732))
2727
- Support running the test suite without `cbor2` installed.
2828
([#748](https://github.com/python-attrs/cattrs/pull/748))
29+
- The [union passthrough strategy](https://catt.rs/en/stable/strategies.html#union-passthrough) now supports PEP 695 type aliases as union members.
30+
([#753](https://github.com/python-attrs/cattrs/pull/753))
2931

3032
## 26.1.0 (2026-02-18)
3133

docs/defaulthooks.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,10 @@ Their hooks can also be overriden using [](customizing.md#predicate-hooks).
640640
Type aliases using [`typing.TypeAlias`](https://docs.python.org/3/library/typing.html#typing.TypeAlias) aren't supported since there is no way at runtime to distinguish them from their underlying types.
641641
```
642642

643+
```{versionchanged} 26.2.0
644+
The [union passthrough strategy](strategies.md#union-passthrough) also recognizes type aliases used as union members.
645+
```
646+
643647
```python
644648
>>> from datetime import datetime, UTC
645649

docs/strategies.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ The strategy also supports [NewTypes](https://mypy.readthedocs.io/en/stable/more
367367
12
368368
```
369369

370+
```{versionchanged} 26.2.0
371+
PEP 695 type aliases of supported types are supported when used as union members.
372+
```
373+
370374
Unions containing unsupported types can be handled if at least one union type is supported by the strategy; the supported union types will be checked before the rest (referred to as the _spillover_) is handed over to the converter again.
371375

372376
For example, if `A` and `B` are arbitrary _attrs_ classes, the union `Literal[10] | A | B` cannot be handled directly by a JSON converter.

src/cattrs/strategies/_unions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ def configure_union_passthrough(
173173
.. versionadded:: 23.2.0
174174
.. versionchanged:: 25.2.0
175175
Introduced the `accept_ints_as_floats` parameter.
176+
.. versionchanged:: 26.2.0
177+
PEP 695 type aliases are now supported as union members.
176178
"""
177179

178180
def get_passthrough_base(type: Any) -> Any:

0 commit comments

Comments
 (0)