Skip to content

Commit 6ec36d3

Browse files
committed
Use type check instead duck-typing
1 parent 7062102 commit 6ec36d3

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

flask_apispec/wrapper.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
# -*- coding: utf-8 -*-
2+
try:
3+
from collections.abc import Mapping
4+
except ImportError: # Python 2
5+
from collections import Mapping
26

3-
from six.moves import http_client as http
47

58
import flask
6-
9+
import marshmallow as ma
710
import werkzeug
11+
from six.moves import http_client as http
812
from webargs import flaskparser
913

1014
from flask_apispec import utils
1115

12-
import marshmallow as ma
1316

1417
MARSHMALLOW_VERSION_INFO = tuple(
1518
[int(part) for part in ma.__version__.split('.') if part.isdigit()]
@@ -43,7 +46,7 @@ def call_view(self, *args, **kwargs):
4346
parsed = parser.parse(schema, locations=option['kwargs']['locations'])
4447
if getattr(schema, 'many', False):
4548
args += tuple(parsed)
46-
elif getattr(parsed, 'update', False):
49+
elif isinstance(parsed, Mapping):
4750
kwargs.update(parsed)
4851
else:
4952
args += (parsed, )

tests/test_views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class User:
3535
def __init__(self, name):
3636
self.name = name
3737

38+
def update(self, name):
39+
self.name = name
40+
3841
class ArgSchema(Schema):
3942
name = fields.Str()
4043

0 commit comments

Comments
 (0)