Marshmallow-dataclass

Latest version: v8.7.1

Safety actively analyzes 688735 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 5 of 7

8.2.0

- Add support for the Literal type. See [110](https://github.com/lovasoa/marshmallow_dataclass/pull/110)

8.1.0

- Improved support for Optional types

8.0.0

- Better support for unions (See [93](https://github.com/lovasoa/marshmallow_dataclass/pull/93)).
- Added support for validator stacking. This breaks backwards compatability. See https://github.com/lovasoa/marshmallow_dataclass/issues/91.
What this means:
python
CustomType = NewType("CustomType", str, validate=marshmallow.validate.Length(min=3))


dataclass
class CustomObject:
some_field: CustomType = field(metadata={"validate": marshmallow.validate.URL()})

The following code will produce a field with the following list of validators: `[marshmallow.validate.Length(min=3), marshmallow.validate.URL()]` instead of the previous: `[marshmallow.validate.URL()]`.

7.6.0

- Allow setting a custom marshmallow field for collection types. This lets you write code such as :
python
class FilteringListField(ListField):
def __init__(self, cls: Union[Field, type], min: typing.Any, **kwargs):
super().__init__(cls, **kwargs)
self.min = min

def _deserialize(self, value, attr, data, **kwargs) -> typing.List[typing.Any]:
loaded = super(FilteringListField, self)._deserialize(
value, attr, data, **kwargs
)
return [x for x in loaded if self.min <= x]


class BaseSchema(Schema):
TYPE_MAPPING = {typing.List: FilteringListField}


dataclasses.dataclass
class WithCustomField:
constrained_floats: typing.List[float] = dataclasses.field(metadata={"min": 1})


schema = class_schema(WithCustomField, base_schema=BaseSchema)()
schema.load({"constrained_floats": [0, 1, 2, 3]})
-> WithCustomField(constrained_floats=[1.0, 2.0, 3.0])

(See [66](https://github.com/lovasoa/marshmallow_dataclass/issues/66))

7.5.2

- Fix fields of type `Any` incorrectly always rejecting the value `None`.
`None` can still be disallowed by explicitly setting the marshmallow attribute `allow_none=False`.
([80](https://github.com/lovasoa/marshmallow_dataclass/issues/80))

7.5.1

- Fix an inconsistency in the behavior of `marshmallow.post_load`.
The input to [`post_load`](https://marshmallow.readthedocs.io/en/stable/extending.html)
hooks was either a dict or a dataclass instance depending on the method name.
It is now always a dict.
([75](https://github.com/lovasoa/marshmallow_dataclass/issues/75))

Page 5 of 7

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.