cattrs.gen package#
Submodules#
cattrs.gen.typeddicts module#
- cattrs.gen.typeddicts.make_dict_structure_fn(cl, converter, _cattrs_forbid_extra_keys=False, _cattrs_use_linecache=True, _cattrs_detailed_validation=True, **kwargs)[source]#
Generate a specialized dict structuring function for typed dicts.
- Parameters
cl (Any) – A TypedDict class.
converter (BaseConverter) – A Converter instance to use for structuring nested fields.
kwargs (AttributeOverride) – A mapping of field names to an AttributeOverride, for customization.
_cattrs_detailed_validation (bool) – Whether to use a slower mode that produces more detailed errors.
_cattrs_forbid_extra_keys (bool) – Whether the structuring function should raise a ForbiddenExtraKeysError if unknown keys are encountered.
_cattrs_detailed_validation – Whether to store the generated code in the _linecache_, for easier debugging and better stack traces.
_cattrs_use_linecache (bool) –
- Return type
Callable[[Dict, Any], Any]
- cattrs.gen.typeddicts.make_dict_unstructure_fn(cl, converter, _cattrs_use_linecache=True, **kwargs)[source]#
Generate a specialized dict unstructuring function for a TypedDict.
- Parameters
cl (Type[T]) – A TypedDict class.
converter (BaseConverter) – A Converter instance to use for unstructuring nested fields.
kwargs (AttributeOverride) – A mapping of field names to an AttributeOverride, for customization.
_cattrs_detailed_validation – Whether to store the generated code in the _linecache_, for easier debugging and better stack traces.
_cattrs_use_linecache (bool) –
- Return type
Callable[[T], Dict[str, Any]]
Module contents#
- cattrs.gen.make_dict_structure_fn(cl, converter, _cattrs_forbid_extra_keys=False, _cattrs_use_linecache=True, _cattrs_prefer_attrib_converters=False, _cattrs_detailed_validation=True, **kwargs)[source]#
Generate a specialized dict structuring function for an attrs class.
- Parameters
cl (Type[T]) –
converter (BaseConverter) –
_cattrs_forbid_extra_keys (bool) –
_cattrs_use_linecache (bool) –
_cattrs_prefer_attrib_converters (bool) –
_cattrs_detailed_validation (bool) –
kwargs (AttributeOverride) –
- Return type
DictStructureFn[T]
- cattrs.gen.make_dict_unstructure_fn(cl, converter, _cattrs_omit_if_default=False, _cattrs_use_linecache=True, **kwargs)[source]#
Generate a specialized dict unstructuring function for an attrs class or a dataclass.
- Parameters
cl (Type[T]) –
converter (BaseConverter) –
_cattrs_omit_if_default (bool) –
_cattrs_use_linecache (bool) –
kwargs (AttributeOverride) –
- Return type
Callable[[T], Dict[str, Any]]
- cattrs.gen.make_hetero_tuple_unstructure_fn(cl, converter, unstructure_to=None)[source]#
Generate a specialized unstructure function for a heterogenous tuple.
- Parameters
cl (Any) –
converter (BaseConverter) –
unstructure_to (Any) –
- Return type
HeteroTupleUnstructureFn
- cattrs.gen.make_iterable_unstructure_fn(cl, converter, unstructure_to=None)[source]#
Generate a specialized unstructure function for an iterable.
- Parameters
cl (Any) –
converter (BaseConverter) –
unstructure_to (Any) –
- Return type
IterableUnstructureFn
- cattrs.gen.make_mapping_structure_fn(cl, converter, structure_to=<class 'dict'>, key_type=_Nothing.NOTHING, val_type=_Nothing.NOTHING, detailed_validation=True)[source]#
Generate a specialized unstructure function for a mapping.
- Parameters
cl (Type[T]) –
converter (BaseConverter) –
structure_to (Type) –
detailed_validation (bool) –
- Return type
MappingStructureFn[T]
- cattrs.gen.make_mapping_unstructure_fn(cl, converter, unstructure_to=None, key_handler=None)[source]#
Generate a specialized unstructure function for a mapping.
- Parameters
cl (Any) –
converter (BaseConverter) –
unstructure_to (Any) –
key_handler (Optional[Callable[[Any, Optional[Any]], Any]]) –
- Return type
MappingUnstructureFn