You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-2Lines changed: 16 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -129,6 +129,7 @@ destructure them.
129
129
-`typing.MutableSet[T]`, `typing.Set[T]` (converts to a set).
130
130
-`typing.FrozenSet[T]` (converts to a frozenset).
131
131
-`typing.Dict[K, V]`, `typing.MutableMapping[K, V]`, `typing.Mapping[K, V]` (converts to a dict).
132
+
-`typing.TypedDict`.
132
133
-_attrs_ classes with simple attributes and the usual `__init__`.
133
134
134
135
- Simple attributes are attributes that can be assigned unstructured data,
@@ -142,6 +143,20 @@ destructure them.
142
143
_cattrs_ comes with preconfigured converters for a number of serialization libraries, including json, msgpack, cbor2, bson, yaml and toml.
143
144
For details, see the [cattr.preconf package](https://catt.rs/en/stable/preconf.html).
144
145
146
+
## Design Decisions
147
+
148
+
_cattrs_ is based on a few fundamental design decisions.
149
+
150
+
- Un/structuring rules are separate from the models.
151
+
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
+
- Invent as little as possible; reuse existing ordinary Python instead.
153
+
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).
154
+
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_.
155
+
- Refuse the temptation to guess.
156
+
If there are two ways of solving a problem, _cattrs_ should refuse to guess and let the user configure it themselves.
157
+
158
+
A foolish consistency is the hobgoblin of little minds so these decisions can and are sometimes broken, but they have proven to be a good foundation.
159
+
145
160
## Additional documentation and talks
146
161
147
162
-[On structured and unstructured data, or the case for cattrs](https://threeofwands.com/on-structured-and-unstructured-data-or-the-case-for-cattrs/)
@@ -151,8 +166,7 @@ For details, see the [cattr.preconf package](https://catt.rs/en/stable/preconf.h
151
166
152
167
## Credits
153
168
154
-
Major credits to Hynek Schlawack for creating [attrs](https://attrs.org) and its predecessor,
Major credits to Hynek Schlawack for creating [attrs](https://attrs.org) and its predecessor, [characteristic](https://github.com/hynek/characteristic).
156
170
157
171
_cattrs_ is tested with [Hypothesis](http://hypothesis.readthedocs.io/en/latest/), by David R. MacIver.
0 commit comments