Modules¶
dict_deserializer.annotations¶
-
class
dict_deserializer.annotations.Discriminator[source]¶ Bases:
abc.ABCBase class for all discriminator.
-
class
dict_deserializer.annotations.FunctionDiscriminator(matcher)[source]¶ Bases:
dict_deserializer.annotations.DiscriminatorDiscriminates according to a custom function.
-
class
dict_deserializer.annotations.KeyValueDiscriminator(key, value, has_value=True)[source]¶ Bases:
dict_deserializer.annotations.DiscriminatorDiscriminates on key and optionally a value.
-
dict_deserializer.annotations.abstract(cls)[source]¶ Declares that this class cannot be instanced. Only subclasses that are not declared abstract could be instanced.
This is equivalent to setting the class property
_abstract=True.Parameters: cls – The class that should be abstract Returns: The same class
-
dict_deserializer.annotations.discriminate(key=None, value=<object object>, matcher=None)[source]¶ Class level annotation to specify requirements of the raw datastructure in order to be allowed to deserialize into this class (or its subclasses).
Parameters: - key – The key to discriminate against
- value – (Optionally) the value that the property designated by
keyshould hold - matcher – (Optionally) a custom function to discriminate with.
Returns: A function that should wrap the class to be discriminated.
-
dict_deserializer.annotations.validated(default=None)[source]¶ Used to decorate a validator function. Can be used if one would want to constrain the value of a property. Of course,
@propertymay be used as well. Throw a TypeError when validation fails.Parameters: default – The default (initial) value of this property Returns: the wrapper function.
dict_deserializer.deserializer¶
-
class
dict_deserializer.deserializer.Deserializable(**kwargs)[source]¶ Bases:
objectBase class for all automagically deserializing classes.
-
class
dict_deserializer.deserializer.DeserializableMeta[source]¶ Bases:
typeMetaclass for all Deserializable
-
class
dict_deserializer.deserializer.Rule(type, default=None)[source]¶ Bases:
objectThis class is primarily used as a container to store type information.
-
dict_deserializer.deserializer.deserialize(rule: dict_deserializer.deserializer.Rule, data, try_all: bool = True, key: str = '[root]')[source]¶ Converts the passed in data into a type that is compatible with rule.
Parameters: - rule –
- data –
- try_all – Whether to attempt other subtypes when a TypeError has occurred. This is useful when automatically deriving discriminators.
- key – Used for exceptions and error reporting. Preferrably the full path to the current value.
Returns: An instance matching Rule.
-
dict_deserializer.deserializer.get_deserialization_classes(t, d, try_all=True) → List[type][source]¶ Find all candidates that are a (sub)type of t, matching d.
Parameters: - t – The type to match from.
- d – The dict to match onto.
- try_all – Whether to support automatic discrimination.
Returns: an ordered list of candidate classes to deserialize into.