cattrs.strategies package#


cattrs.strategies.subclasses module#

Module contents#

High level strategies for converters.

cattrs.strategies.configure_tagged_union(union, converter, tag_generator=<function default_tag_generator>, tag_name='_type', default=_Nothing.NOTHING)[source]#

Configure the converter so that union (which should be a union) is un/structured with the help of an additional piece of data in the unstructured payload, the tag.

  • converter (Converter) – The converter to apply the strategy to.

  • tag_generator (Callable[[Type], str]) – A tag_generator function is used to map each member of the union to a tag, which is then included in the unstructured payload. The default tag generator returns the name of the class.

  • tag_name (str) – The key under which the tag will be set in the unstructured payload. By default, ‘_type’.

  • default (Optional[Type]) – An optional class to be used if the tag information is not present when structuring.

  • union (Any) –

Return type


The tagged union strategy currently only works with the dict un/structuring base strategy.

New in version 22.3.0.