Skip to content

Commit

Permalink
Use marshmallow 3's from_dict if available
Browse files Browse the repository at this point in the history
  • Loading branch information
sloria committed Aug 17, 2019
1 parent d412abb commit 62dd90e
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/webargs/dict2schema.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
# -*- coding: utf-8 -*-
import marshmallow as ma

from webargs.compat import MARSHMALLOW_VERSION_INFO


def dict2schema(dct, schema_class=ma.Schema):
"""Generate a `marshmallow.Schema` class given a dictionary of
`Fields <marshmallow.fields.Field>`.
"""
if hasattr(schema_class, "from_dict"): # marshmallow 3
return schema_class.from_dict(dct)
attrs = dct.copy()

class Meta(object):
if MARSHMALLOW_VERSION_INFO[0] < 3:
strict = True
else:
register = False
strict = True

attrs["Meta"] = Meta
return type(str(""), (schema_class,), attrs)

0 comments on commit 62dd90e

Please sign in to comment.