Skip to content

Commit 9311a4d

Browse files
committed
Tweak docs
1 parent 7c569d6 commit 9311a4d

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

HISTORY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
- **Potentially breaking**: {py:func}`cattrs.gen.make_dict_structure_fn` and {py:func}`cattrs.gen.typeddicts.make_dict_structure_fn` will use the values for the `detailed_validation` and `forbid_extra_keys` parameters from the given converter by default now.
99
If you're using these functions directly, the old behavior can be restored by passing in the desired values directly.
1010
([#410](https://github.com/python-attrs/cattrs/issues/410) [#411](https://github.com/python-attrs/cattrs/pull/411))
11+
- Introduce the `use_class_methods` strategy. Learn more [here](https://catt.rs/en/latest/strategies.html#using-class-specific-structure-and-unstructure-methods).
12+
([#405](https://github.com/python-attrs/cattrs/pull/405))
1113
- The `omit` parameter of {py:func}`cattrs.override` is now of type `bool | None` (from `bool`).
1214
`None` is the new default and means to apply default _cattrs_ handling to the attribute, which is to omit the attribute if it's marked as `init=False`, and keep it otherwise.
1315
- Fix {py:func}`format_exception() <cattrs.v.format_exception>` parameter working for recursive calls to {py:func}`transform_error <cattrs.transform_error>`.
@@ -39,7 +41,6 @@
3941
- Add support for `date` to preconfigured converters.
4042
([#420](https://github.com/python-attrs/cattrs/pull/420))
4143

42-
4344
## 23.1.2 (2023-06-02)
4445

4546
- Improve `typing_extensions` version bound. ([#372](https://github.com/python-attrs/cattrs/issues/372))

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ _cattrs_ is based on a few fundamental design decisions.
149149

150150
- Un/structuring rules are separate from the models.
151151
This allows models to have a one-to-many relationship with un/structuring rules, and to create un/structuring rules for models which you do not own and you cannot change.
152+
(_cattrs_ can be configured to use un/structuring rules from models using the [`use_class_methods` strategy](https://catt.rs/en/latest/strategies.html#using-class-specific-structure-and-unstructure-methods).)
152153
- Invent as little as possible; reuse existing ordinary Python instead.
153154
For example, _cattrs_ did not have a custom exception type to group exceptions until the sanctioned Python [`exceptiongroups`](https://docs.python.org/3/library/exceptions.html#ExceptionGroup).
154155
A side-effect of this design decision is that, in a lot of cases, when you're solving _cattrs_ problems you're actually learning Python instead of learning _cattrs_.
@@ -163,6 +164,7 @@ A foolish consistency is the hobgoblin of little minds so these decisions can an
163164
- [Why I use attrs instead of pydantic](https://threeofwands.com/why-i-use-attrs-instead-of-pydantic/)
164165
- [cattrs I: un/structuring speed](https://threeofwands.com/why-cattrs-is-so-fast/)
165166
- [Python has a macro language - it's Python (PyCon IT 2022)](https://www.youtube.com/watch?v=UYRSixikUTo)
167+
- [Intro to cattrs 23.1](https://threeofwands.com/intro-to-cattrs-23-1-0/)
166168

167169
## Credits
168170

docs/strategies.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ Child2(a=1, b=1)
221221
```
222222

223223
Other customizations available see are (see {py:func}`include_subclasses()<cattrs.strategies.include_subclasses>`):
224+
224225
- The exact list of subclasses that should participate to the union with the `subclasses` argument.
225226
- Attribute overrides that permit the customization of attributes un/structuring like renaming an attribute.
226227

@@ -259,13 +260,12 @@ Child(a=1, b='foo')
259260
260261
```
261262

262-
263-
264-
### Using Class-Specific Structure and Unstructure Methods
263+
## Using Class-Specific Structure and Unstructure Methods
265264

266265
_Found at {py:func}`cattrs.strategies.use_class_methods`._
267266

268-
The following strategy can be applied for both structuring and unstructuring (also simultaneously).
267+
This strategy allows for un/structuring logic on the models themselves.
268+
It can be applied for both structuring and unstructuring (also simultaneously).
269269

270270
If a class requires special handling for (un)structuring, you can add a dedicated (un)structuring
271271
method:
@@ -295,11 +295,11 @@ MyClass(a=43)
295295
{'c': 41}
296296
```
297297

298-
Any class without a `_structure` or `_unstructure` method will use the default strategy for
299-
structuring or unstructuring, respectively. Feel free to use other names.
298+
Any class without a `_structure` or `_unstructure` method will use the default strategy for structuring or unstructuring, respectively.
299+
Feel free to use other names.
300+
The stategy can be applied multiple times (with different method names).
300301

301-
If you want to (un)structured nested objects, just append a converter parameter
302-
to your (un)structuring methods and you will receive the converter there:
302+
If you want to (un)structured nested objects, just append a converter parameter to your (un)structuring methods and you will receive the converter there:
303303

304304
```{doctest} class_methods
305305

0 commit comments

Comments
 (0)