Skip to content

Commit

Permalink
Improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinche committed Oct 1, 2022
1 parent 430f0d6 commit 85c5f49
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,4 @@
"from enum import Enum, unique"
)
autodoc_typehints = "description"
autosectionlabel_prefix_document = True
6 changes: 5 additions & 1 deletion docs/structuring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ To support arbitrary unions, register a custom structuring hook for the union
`PEP 593`_ annotations (``typing.Annotated[type, ...]``) are supported and are
matched using the first type present in the annotated type.
.. _structuring_newtypes:
``typing.NewType``
~~~~~~~~~~~~~~~~~~
Expand All @@ -291,6 +293,8 @@ Their hooks can also be overriden using :py:attr:`cattrs.Converter.register_stru
.. versionadded:: 22.2.0
.. seealso:: :ref:`Unstructuring NewTypes. <unstructuring_newtypes>`
.. note::
NewTypes are not supported by the legacy BaseConverter.
Expand Down Expand Up @@ -500,7 +504,7 @@ Here's a small example showing how to use factory hooks to apply the `forbid_ext
cattrs.errors.ForbiddenExtraKeysError: Extra fields in constructor for E: else
A complex use case for hook factories is described over at :ref:`Using factory hooks`.
A complex use case for hook factories is described over at :ref:`usage:Using factory hooks`.
.. _`PEP 593` : https://www.python.org/dev/peps/pep-0593/
.. _`NewTypes`: https://docs.python.org/3/library/typing.html#newtype
8 changes: 6 additions & 2 deletions docs/unstructuring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ from ``typing`` on older Python versions.
Fields marked as ``typing.Annotated[type, ...]`` are supported and are matched
using the first type present in the annotated type.

.. _unstructuring_newtypes:

``typing.NewType``
------------------

Expand All @@ -104,14 +106,16 @@ Their hooks can also be overriden using :py:attr:`cattrs.Converter.register_unst

.. versionadded:: 22.2.0

.. seealso:: :ref:`Structuring NewTypes. <structuring_newtypes>`

.. note::
NewTypes are not supported by the legacy BaseConverter.

``attrs`` classes and dataclasses
---------------------------------

``attrs`` classes and dataclasses are supported out of the box.
:class:`.Converter` s support two unstructuring strategies:
:class:`cattrs.Converter` s support two unstructuring strategies:

* ``UnstructureStrategy.AS_DICT`` - similar to ``attr.asdict``, unstructures ``attrs`` and dataclass instances into dictionaries. This is the default.
* ``UnstructureStrategy.AS_TUPLE`` - similar to ``attr.astuple``, unstructures ``attrs`` and dataclass instances into tuples.
Expand Down Expand Up @@ -210,6 +214,6 @@ Here's a small example showing how to use factory hooks to skip unstructuring
{'an_int': 1}


A complex use case for hook factories is described over at :ref:`Using factory hooks`.
A complex use case for hook factories is described over at :ref:`usage:Using factory hooks`.

.. _`NewTypes`: https://docs.python.org/3/library/typing.html#newtype

0 comments on commit 85c5f49

Please sign in to comment.