Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
cattrs.converters.BaseConverter Class Reference
Inheritance diagram for cattrs.converters.BaseConverter:
Inheritance graph
[legend]

Public Member Functions

None __init__ (self, Callable[[], Any] dict_factory=dict, UnstructureStrategy unstruct_strat=UnstructureStrategy.AS_DICT, bool prefer_attrib_converters=False, bool detailed_validation=True, HookFactory[UnstructureHook] unstructure_fallback_factory=lambda _:identity, HookFactory[StructureHook] structure_fallback_factory=lambda _:raise_error)
 
Any unstructure (self, Any obj, Any unstructure_as=None)
 
UnstructureStrategy unstruct_strat (self)
 
UnstructureHookT register_unstructure_hook (self, UnstructureHookT cls)
 
None register_unstructure_hook (self, Any cls, UnstructureHook func)
 
Callable[[UnstructureHook]]|None register_unstructure_hook (self, Any cls=None, UnstructureHook|None func=None)
 
None register_unstructure_hook_func (self, Predicate check_func, UnstructureHook func)
 
Callable[[AnyUnstructureHookFactoryBase], AnyUnstructureHookFactoryBase] register_unstructure_hook_factory (self, Predicate predicate)
 
UnstructureHookFactory register_unstructure_hook_factory (self, Predicate predicate, UnstructureHookFactory factory)
 
ExtendedUnstructureHookFactory[BaseConverterregister_unstructure_hook_factory (self, Predicate predicate, ExtendedUnstructureHookFactory[BaseConverter] factory)
 
 register_unstructure_hook_factory (self, predicate, factory=None)
 
UnstructureHook get_unstructure_hook (self, Any type, bool cache_result=True)
 
StructureHookT register_structure_hook (self, StructureHookT cl)
 
None register_structure_hook (self, Any cl, StructureHook func)
 
None register_structure_hook (self, Any cl, StructureHook|None func=None)
 
None register_structure_hook_func (self, Predicate check_func, StructureHook func)
 
Callable[[AnyStructureHookFactoryBase], AnyStructureHookFactoryBase] register_structure_hook_factory (self, Predicate predicate)
 
StructureHookFactory register_structure_hook_factory (self, Predicate predicate, StructureHookFactory factory)
 
ExtendedStructureHookFactory[BaseConverterregister_structure_hook_factory (self, Predicate predicate, ExtendedStructureHookFactory[BaseConverter] factory)
 
 register_structure_hook_factory (self, predicate, factory=None)
 
structure (self, UnstructuredValue obj, type[T] cl)
 
StructureHook get_structure_hook (self, Any type, bool cache_result=True)
 
dict[str, Any] unstructure_attrs_asdict (self, Any obj)
 
tuple[Any,...] unstructure_attrs_astuple (self, Any obj)
 
structure_attrs_fromtuple (self, tuple[Any,...] obj, type[T] cl)
 
structure_attrs_fromdict (self, Mapping[str, Any] obj, type[T] cl)
 
BaseConverter __deepcopy__ (self, _)
 
BaseConverter copy (self, Callable[[], Any]|None dict_factory=None, UnstructureStrategy|None unstruct_strat=None, bool|None prefer_attrib_converters=None, bool|None detailed_validation=None)
 

Public Attributes

 detailed_validation
 
 unstructure
 

Protected Member Functions

Any _unstructure_enum (self, Enum obj)
 
Sequence[T] _unstructure_seq (self, Sequence[T] seq)
 
Mapping[T, V] _unstructure_mapping (self, Mapping[T, V] mapping)
 
Any _unstructure_union (self, Any obj)
 
DictStructureFn[T] _gen_structure_generic (self, type[T] cl)
 
Callable[[Any, type[T]], type[T]|None] _gen_attrs_union_structure (self, Any cl, bool use_literals=True)
 
StructuredValue _structure_newtype (self, UnstructuredValue val, type)
 
StructureHook _find_type_alias_structure_hook (self, Any type)
 
 _structure_final_factory (self, type)
 
Any _structure_attribute (self, Attribute|Field a, Any value)
 
deque[T] _structure_deque (self, Iterable[T] obj, Any cl)
 
Set[T] _structure_set (self, Iterable[T] obj, Any cl, type structure_to=set)
 
FrozenSetSubscriptable[T] _structure_frozenset (self, Iterable[T] obj, Any cl)
 
dict[T, V] _structure_dict (self, Mapping[T, V] obj, Any cl)
 
 _structure_optional (self, obj, union)
 
_structure_tuple (self, Any obj, type[T] tup)
 
Callable[[Any], type] _get_dis_func (self, Any union, bool use_literals=True, dict[str, AttributeOverride]|None overrides=None)
 

Static Protected Member Functions

Any _structure_call (Any obj, type[T] cl)
 
 _structure_simple_literal (val, type)
 
 _structure_enum_literal (val, type)
 

Protected Attributes

 _prefer_attrib_converters
 
 _unstructure_attrs
 
 _structure_attrs
 
 _unstructure_func
 
 _unstructure_mapping
 
 _unstructure_seq
 
 _unstructure_enum
 
 _unstructure_union
 
 _structure_func
 
 _gen_structure_generic
 
 _structure_newtype
 
 _find_type_alias_structure_hook
 
 _structure_final_factory
 
 _structure_simple_literal
 
 _structure_enum_literal
 
 _structure_deque
 
 _structure_set
 
 _structure_frozenset
 
 _structure_tuple
 
 _structure_dict
 
 _gen_attrs_union_structure
 
 _structure_optional
 
 _union_struct_registry
 
 _structure_call
 
 _dict_factory
 
 _unstruct_copy_skip
 
 _struct_copy_skip
 

Detailed Description

Converts between structured and unstructured data.

Constructor & Destructor Documentation

◆ __init__()

None cattrs.converters.BaseConverter.__init__ (   self,
Callable[[], Any]   dict_factory = dict,
UnstructureStrategy   unstruct_strat = UnstructureStrategy.AS_DICT,
bool   prefer_attrib_converters = False,
bool   detailed_validation = True,
HookFactory[UnstructureHook]   unstructure_fallback_factory = lambda _: identity,
HookFactory[StructureHook]   structure_fallback_factory = lambda _: raise_error 
)
:param detailed_validation: Whether to use a slightly slower mode for detailed
    validation errors.
:param unstructure_fallback_factory: A hook factory to be called when no
    registered unstructuring hooks match.
:param structure_fallback_factory: A hook factory to be called when no
    registered structuring hooks match.

..  versionadded:: 23.2.0 *unstructure_fallback_factory*
..  versionadded:: 23.2.0 *structure_fallback_factory*

Reimplemented in cattrs.converters.Converter.

Member Function Documentation

◆ _gen_attrs_union_structure()

Callable[[Any, type[T]], type[T] | None] cattrs.converters.BaseConverter._gen_attrs_union_structure (   self,
Any  cl,
bool   use_literals = True 
)
protected
Generate a structuring function for a union of attrs classes (and maybe None).

:param use_literals: Whether to consider literal fields.

◆ _gen_structure_generic()

DictStructureFn[T] cattrs.converters.BaseConverter._gen_structure_generic (   self,
type[T]  cl 
)
protected
Create and return a hook for structuring generics.

◆ _get_dis_func()

Callable[[Any], type] cattrs.converters.BaseConverter._get_dis_func (   self,
Any  union,
bool   use_literals = True,
dict[str, AttributeOverride] | None   overrides = None 
)
protected
Fetch or try creating a disambiguation function for a union.

◆ _structure_attribute()

Any cattrs.converters.BaseConverter._structure_attribute (   self,
Attribute | Field  a,
Any  value 
)
protected
Handle an individual attrs attribute.

◆ _structure_call()

Any cattrs.converters.BaseConverter._structure_call ( Any  obj,
type[T]  cl 
)
staticprotected
Just call ``cl`` with the given ``obj``.

This is just an optimization on the ``_structure_default`` case, when
we know we can skip the ``if`` s. Use for ``str``, ``bytes``, ``enum``,
etc.

◆ _structure_deque()

deque[T] cattrs.converters.BaseConverter._structure_deque (   self,
Iterable[T]  obj,
Any  cl 
)
protected
Convert an iterable to a potentially generic deque.

◆ _structure_dict()

dict[T, V] cattrs.converters.BaseConverter._structure_dict (   self,
Mapping[T, V]  obj,
Any  cl 
)
protected
Convert a mapping into a potentially generic dict.

◆ _structure_frozenset()

FrozenSetSubscriptable[T] cattrs.converters.BaseConverter._structure_frozenset (   self,
Iterable[T]  obj,
Any   cl 
)
protected
Convert an iterable into a potentially generic frozenset.

◆ _structure_set()

Set[T] cattrs.converters.BaseConverter._structure_set (   self,
Iterable[T]  obj,
Any  cl,
type   structure_to = set 
)
protected
Convert an iterable into a potentially generic set.

◆ _structure_tuple()

T cattrs.converters.BaseConverter._structure_tuple (   self,
Any  obj,
type[T]  tup 
)
protected
Deal with structuring into a tuple.

◆ _unstructure_enum()

Any cattrs.converters.BaseConverter._unstructure_enum (   self,
Enum  obj 
)
protected
Convert an enum to its value.

◆ _unstructure_mapping()

Mapping[T, V] cattrs.converters.BaseConverter._unstructure_mapping (   self,
Mapping[T, V]  mapping 
)
protected
Convert a mapping of attr classes to primitive equivalents.

◆ _unstructure_seq()

Sequence[T] cattrs.converters.BaseConverter._unstructure_seq (   self,
Sequence[T]  seq 
)
protected
Convert a sequence to primitive equivalents.

◆ _unstructure_union()

Any cattrs.converters.BaseConverter._unstructure_union (   self,
Any  obj 
)
protected
Unstructure an object as a union.

By default, just unstructures the instance.

◆ copy()

BaseConverter cattrs.converters.BaseConverter.copy (   self,
Callable[[], Any] | None   dict_factory = None,
UnstructureStrategy | None   unstruct_strat = None,
bool | None   prefer_attrib_converters = None,
bool | None   detailed_validation = None 
)
Create a copy of the converter, keeping all existing custom hooks.

:param detailed_validation: Whether to use a slightly slower mode for detailed
    validation errors.

Reimplemented in cattrs.converters.Converter.

◆ get_structure_hook()

StructureHook cattrs.converters.BaseConverter.get_structure_hook (   self,
Any  type,
bool   cache_result = True 
)
Get the structure hook for the given type.

This hook can be manually called, or composed with other functions
and re-registered.

If no hook is registered, the converter structure fallback factory
will be used to produce one.

:param cache: Whether to cache the returned hook.

.. versionadded:: 24.1.0

◆ get_unstructure_hook()

UnstructureHook cattrs.converters.BaseConverter.get_unstructure_hook (   self,
Any  type,
bool   cache_result = True 
)
Get the unstructure hook for the given type.

This hook can be manually called, or composed with other functions
and re-registered.

If no hook is registered, the converter unstructure fallback factory
will be used to produce one.

:param cache: Whether to cache the returned hook.

.. versionadded:: 24.1.0

◆ register_structure_hook()

None cattrs.converters.BaseConverter.register_structure_hook (   self,
Any  cl,
StructureHook | None   func = None 
)
Register a primitive-to-class converter function for a type.

The converter function should take two arguments:
  * a Python object to be converted,
  * the type to convert to

and return the instance of the class. The type may seem redundant, but
is sometimes needed (for example, when dealing with generic classes).

This method may be used as a decorator. In this case, the decorated
hook must have a return type annotation, and this annotation will be used
as the type for the hook.

.. versionchanged:: 24.1.0
    This method may now be used as a decorator.

◆ register_structure_hook_factory()

cattrs.converters.BaseConverter.register_structure_hook_factory (   self,
  predicate,
  factory = None 
)
Register a hook factory for a given predicate.

The hook factory may expose an additional required parameter. In this case,
the current converter will be provided to the hook factory as that
parameter.

May also be used as a decorator.

:param predicate: A function that, given a type, returns whether the factory
    can produce a hook for that type.
:param factory: A callable that, given a type, produces a structuring
    hook for that type. This structuring hook will be cached.

.. versionchanged:: 24.1.0
    This method may now be used as a decorator.
    The factory may also receive the converter as a second, required argument.

◆ register_structure_hook_func()

None cattrs.converters.BaseConverter.register_structure_hook_func (   self,
Predicate  check_func,
StructureHook   func 
)
Register a class-to-primitive converter function for a class, using
a function to check if it's a match.

◆ register_unstructure_hook()

Callable[[UnstructureHook]] | None cattrs.converters.BaseConverter.register_unstructure_hook (   self,
Any   cls = None,
UnstructureHook | None   func = None 
)
Register a class-to-primitive converter function for a class.

The converter function should take an instance of the class and return
its Python equivalent.

May also be used as a decorator. When used as a decorator, the first
argument annotation from the decorated function will be used as the
type to register the hook for.

.. versionchanged:: 24.1.0
    This method may now be used as a decorator.

◆ register_unstructure_hook_factory()

cattrs.converters.BaseConverter.register_unstructure_hook_factory (   self,
  predicate,
  factory = None 
)
Register a hook factory for a given predicate.

The hook factory may expose an additional required parameter. In this case,
the current converter will be provided to the hook factory as that
parameter.

May also be used as a decorator.

:param predicate: A function that, given a type, returns whether the factory
    can produce a hook for that type.
:param factory: A callable that, given a type, produces an unstructuring
    hook for that type. This unstructuring hook will be cached.

.. versionchanged:: 24.1.0
    This method may now be used as a decorator.
    The factory may also receive the converter as a second, required argument.

◆ register_unstructure_hook_func()

None cattrs.converters.BaseConverter.register_unstructure_hook_func (   self,
Predicate  check_func,
UnstructureHook   func 
)
Register a class-to-primitive converter function for a class, using
a function to check if it's a match.

◆ structure()

T cattrs.converters.BaseConverter.structure (   self,
UnstructuredValue  obj,
type[T]  cl 
)
Convert unstructured Python data structures to structured data.

◆ structure_attrs_fromdict()

T cattrs.converters.BaseConverter.structure_attrs_fromdict (   self,
Mapping[str, Any]  obj,
type[T]  cl 
)
Instantiate an attrs class from a mapping (dict).

◆ structure_attrs_fromtuple()

T cattrs.converters.BaseConverter.structure_attrs_fromtuple (   self,
tuple[Any, ...]  obj,
type[T]  cl 
)
Load an attrs class from a sequence (tuple).

◆ unstruct_strat()

UnstructureStrategy cattrs.converters.BaseConverter.unstruct_strat (   self)
The default way of unstructuring ``attrs`` classes.

◆ unstructure_attrs_asdict()

dict[str, Any] cattrs.converters.BaseConverter.unstructure_attrs_asdict (   self,
Any  obj 
)
Our version of `attrs.asdict`, so we can call back to us.

◆ unstructure_attrs_astuple()

tuple[Any, ...] cattrs.converters.BaseConverter.unstructure_attrs_astuple (   self,
Any  obj 
)
Our version of `attrs.astuple`, so we can call back to us.

The documentation for this class was generated from the following file: