Repository: marshmallow-code/webargs

Issue:
Pyramid parser use_kwargs throws exception when used
The following code using the pyramid parser throws an exception:

``` python
@parser.use_kwargs({'myvalue': Arg(int)})
def baz(request, myvalue):
    return {'myvalue': myvalue}
```

The exception:

```
        kwargs['as_kwargs'] = True
>       return self.use_args(*args, **kwargs)
E       TypeError: use_args() got an unexpected keyword argument 'as_kwargs'
```

Pyramid parser use_kwargs throws exception when used
The following code using the pyramid parser throws an exception:

``` python
@parser.use_kwargs({'myvalue': Arg(int)})
def baz(request, myvalue):
    return {'myvalue': myvalue}
```

The exception:

```
        kwargs['as_kwargs'] = True
>       return self.use_args(*args, **kwargs)
E       TypeError: use_args() got an unexpected keyword argument 'as_kwargs'
```



Discussion:

Resolving patch:
diff --git a/webargs/pyramidparser.py b/webargs/pyramidparser.py
--- a/webargs/pyramidparser.py
+++ b/webargs/pyramidparser.py
@@ -79,7 +79,7 @@ def handle_error(self, error):
         raise exception_response(status_code, detail=text_type(error), **data)
 
     def use_args(self, argmap, req=None, locations=core.Parser.DEFAULT_LOCATIONS,
-                 validate=None):
+                 as_kwargs=False, validate=None):
         """Decorator that injects parsed arguments into a view callable.
         Supports the *Class-based View* pattern where `request` is saved as an instance
         attribute on a view class.
@@ -102,7 +102,11 @@ def wrapper(obj, *args, **kwargs):
                     request = obj
                 parsed_args = self.parse(argmap, req=request, locations=locations,
                                          validate=None)
-                return func(obj, parsed_args, *args, **kwargs)
+                if as_kwargs:
+                    kwargs.update(parsed_args)
+                    return func(obj, *args, **kwargs)
+                else:
+                    return func(obj, parsed_args, *args, **kwargs)
             return wrapper
         return decorator
 


Test patch:
diff --git a/tests/test_pyramidparser.py b/tests/test_pyramidparser.py
--- a/tests/test_pyramidparser.py
+++ b/tests/test_pyramidparser.py
@@ -61,6 +61,10 @@ def __init__(self, request):
         def __call__(self, args):
             return args
 
+    @parser.use_kwargs({'myvalue': Arg(int)})
+    def baz(request, myvalue):
+        return {'myvalue': myvalue}
+
     config = Configurator()
 
     config.add_route('echo', '/echo')
@@ -71,6 +75,7 @@ def __call__(self, args):
     config.add_route('echofile', '/echofile')
     config.add_route('foo', '/foo')
     config.add_route('bar', '/bar')
+    config.add_route('baz', '/baz')
 
     config.add_view(echo, route_name='echo', renderer='json')
     config.add_view(echomulti, route_name='echomulti', renderer='json')
@@ -80,6 +85,7 @@ def __call__(self, args):
     config.add_view(echofile, route_name='echofile', renderer='json')
     config.add_view(foo, route_name='foo', renderer='json')
     config.add_view(Bar, route_name='bar', renderer='json')
+    config.add_view(baz, route_name='baz', renderer='json')
 
     app = config.make_wsgi_app()
 
@@ -134,3 +140,6 @@ def test_use_args_decorator(testapp):
 
 def test_use_args_decorator_class(testapp):
     assert testapp.post('/bar', {'myvalue': 42}).json == {'myvalue': 42}
+
+def test_user_kwargs_decorator(testapp):
+    assert testapp.post('/baz', {'myvalue': 42}).json == {'myvalue': 42}