Skip to content

Instantly share code, notes, and snippets.

@mvantellingen
Last active April 5, 2019 12:19
Show Gist options
  • Save mvantellingen/a879bd07d844519613493c9b91dd35ff to your computer and use it in GitHub Desktop.
Save mvantellingen/a879bd07d844519613493c9b91dd35ff to your computer and use it in GitHub Desktop.
import attr, marshmallow, typing
@attr.s(auto_attribs=True, init=False, repr=False)
class Price:
id: typing.Optional[str]
def __init__(self, *, id: typing.Optional[str] = None) -> None:
self.id = id
def __repr__(self) -> str:
return "Price(id=%r)" % (self.id)
class PriceSchema(marshmallow.Schema):
id = marshmallow.fields.String(allow_none=True, missing=None)
class Meta:
unknown = marshmallow.EXCLUDE
@marshmallow.post_load
def post_load(self, data):
return types.Price(**data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment