We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
@validate_arguments on instance methods
# Bug

Hello, I tried using the new `@validate_arguments` decorator and it doesn't work when used on instance methods.

I didn't see it on the ToDo in #1205 and it seems like an oversight, maybe due to the special treatment of `self`.

Output of `python -c "import pydantic.utils; print(pydantic.utils.version_info())"`:
```
$ python3 -c "import pydantic.utils; print(pydantic.utils.version_info())"
             pydantic version: 1.4a1
            pydantic compiled: False
                 install path: /home/[user]/git/pydantic/pydantic
               python version: 3.7.5 (default, Nov 20 2019, 09:21:52)  [GCC 9.2.1 20191008]
                     platform: Linux-5.3.0-29-generic-x86_64-with-Ubuntu-19.10-eoan
     optional deps. installed: []
```


```py
from pydantic import validate_arguments


class SomeObject:
    @validate_arguments
    def some_function(self, i: int):
        print(type(self), self)
        print(type(i), i)

o = SomeObject()
o.some_function(1)  # doesn't work, instead of `i` `self` becomes 1
#pydantic.error_wrappers.ValidationError: 1 validation error for SomeFunction
#i
#  field required (type=value_error.missing)

o.some_function(o, 1)  # works, but not the way instance methods are meant to be used
#<class '__main__.SomeObject'> <__main__.SomeObject object at 0x7f32911af3d0>
#<class 'int'> 1
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pydantic/decorator.py`
Content:
```
1 from functools import update_wrapper
2 from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Tuple, TypeVar, cast, get_type_hints
3 
4 from . import validator
5 from .errors import ConfigError
6 from .main import BaseModel, Extra, create_model
7 from .utils import to_camel
8 
9 __all__ = ('validate_arguments',)
10 
11 if TYPE_CHECKING:
12     from .typing import AnyCallable
13 
14     Callable = TypeVar('Callable', bound=AnyCallable)
15 
16 
17 def validate_arguments(function: 'Callable') -> 'Callable':
18     """
19     Decorator to validate the arguments passed to a function.
20     """
21     vd = ValidatedFunction(function)
22     vd = update_wrapper(vd, function)  # type: ignore
23     return cast('Callable', vd)
24 
25 
26 ALT_V_ARGS = 'v__args'
27 ALT_V_KWARGS = 'v__kwargs'
28 V_POSITIONAL_ONLY_NAME = 'v__positional_only'
29 
30 
31 class ValidatedFunction:
32     def __init__(self, function: 'Callable'):
33         from inspect import signature, Parameter
34 
35         parameters: Mapping[str, Parameter] = signature(function).parameters
36 
37         if parameters.keys() & {ALT_V_ARGS, ALT_V_KWARGS, V_POSITIONAL_ONLY_NAME}:
38             raise ConfigError(
39                 f'"{ALT_V_ARGS}", "{ALT_V_KWARGS}" and "{V_POSITIONAL_ONLY_NAME}" are not permitted as argument '
40                 f'names when using the "{validate_arguments.__name__}" decorator'
41             )
42 
43         self.raw_function = function
44         self.arg_mapping: Dict[int, str] = {}
45         self.positional_only_args = set()
46         self.v_args_name = 'args'
47         self.v_kwargs_name = 'kwargs'
48 
49         type_hints = get_type_hints(function)
50         takes_args = False
51         takes_kwargs = False
52         fields: Dict[str, Tuple[Any, Any]] = {}
53         for i, (name, p) in enumerate(parameters.items()):
54             if p.annotation == p.empty:
55                 annotation = Any
56             else:
57                 annotation = type_hints[name]
58 
59             default = ... if p.default == p.empty else p.default
60             if p.kind == Parameter.POSITIONAL_ONLY:
61                 self.arg_mapping[i] = name
62                 fields[name] = annotation, default
63                 fields[V_POSITIONAL_ONLY_NAME] = List[str], None
64                 self.positional_only_args.add(name)
65             elif p.kind == Parameter.POSITIONAL_OR_KEYWORD:
66                 self.arg_mapping[i] = name
67                 fields[name] = annotation, default
68             elif p.kind == Parameter.KEYWORD_ONLY:
69                 fields[name] = annotation, default
70             elif p.kind == Parameter.VAR_POSITIONAL:
71                 self.v_args_name = name
72                 fields[name] = Tuple[annotation, ...], None
73                 takes_args = True
74             else:
75                 assert p.kind == Parameter.VAR_KEYWORD, p.kind
76                 self.v_kwargs_name = name
77                 fields[name] = Dict[str, annotation], None  # type: ignore
78                 takes_kwargs = True
79 
80         # these checks avoid a clash between "args" and a field with that name
81         if not takes_args and self.v_args_name in fields:
82             self.v_args_name = ALT_V_ARGS
83 
84         # same with "kwargs"
85         if not takes_kwargs and self.v_kwargs_name in fields:
86             self.v_kwargs_name = ALT_V_KWARGS
87 
88         if not takes_args:
89             # we add the field so validation below can raise the correct exception
90             fields[self.v_args_name] = List[Any], None
91 
92         if not takes_kwargs:
93             # same with kwargs
94             fields[self.v_kwargs_name] = Dict[Any, Any], None
95 
96         self.create_model(fields, takes_args, takes_kwargs)
97 
98     def __call__(self, *args: Any, **kwargs: Any) -> Any:
99         values = self.build_values(args, kwargs)
100         m = self.model(**values)
101         return self.execute(m)
102 
103     def build_values(self, args: Tuple[Any, ...], kwargs: Dict[str, Any]) -> Dict[str, Any]:
104         values: Dict[str, Any] = {}
105         if args:
106             arg_iter = enumerate(args)
107             while True:
108                 try:
109                     i, a = next(arg_iter)
110                 except StopIteration:
111                     break
112                 arg_name = self.arg_mapping.get(i)
113                 if arg_name is not None:
114                     values[arg_name] = a
115                 else:
116                     values[self.v_args_name] = [a] + [a for _, a in arg_iter]
117                     break
118 
119         var_kwargs = {}
120         wrong_positional_args = []
121         for k, v in kwargs.items():
122             if k in self.model.__fields__:
123                 if k in self.positional_only_args:
124                     wrong_positional_args.append(k)
125                 values[k] = v
126             else:
127                 var_kwargs[k] = v
128 
129         if var_kwargs:
130             values[self.v_kwargs_name] = var_kwargs
131         if wrong_positional_args:
132             values[V_POSITIONAL_ONLY_NAME] = wrong_positional_args
133         return values
134 
135     def execute(self, m: BaseModel) -> Any:
136         d = {k: v for k, v in m._iter() if k in m.__fields_set__}
137         kwargs = d.pop(self.v_kwargs_name, None)
138         if kwargs:
139             d.update(kwargs)
140 
141         if self.v_args_name in d:
142             args_: List[Any] = []
143             in_kwargs = False
144             kwargs = {}
145             for name, value in d.items():
146                 if in_kwargs:
147                     kwargs[name] = value
148                 elif name == self.v_args_name:
149                     args_ += value
150                     in_kwargs = True
151                 else:
152                     args_.append(value)
153             return self.raw_function(*args_, **kwargs)
154         elif self.positional_only_args:
155             args_ = []
156             kwargs = {}
157             for name, value in d.items():
158                 if name in self.positional_only_args:
159                     args_.append(value)
160                 else:
161                     kwargs[name] = value
162             return self.raw_function(*args_, **kwargs)
163         else:
164             return self.raw_function(**d)
165 
166     def create_model(self, fields: Dict[str, Any], takes_args: bool, takes_kwargs: bool) -> None:
167         pos_args = len(self.arg_mapping)
168 
169         class DecoratorBaseModel(BaseModel):
170             @validator(self.v_args_name, check_fields=False, allow_reuse=True)
171             def check_args(cls, v: List[Any]) -> List[Any]:
172                 if takes_args:
173                     return v
174 
175                 raise TypeError(f'{pos_args} positional arguments expected but {pos_args + len(v)} given')
176 
177             @validator(self.v_kwargs_name, check_fields=False, allow_reuse=True)
178             def check_kwargs(cls, v: Dict[str, Any]) -> Dict[str, Any]:
179                 if takes_kwargs:
180                     return v
181 
182                 plural = '' if len(v) == 1 else 's'
183                 keys = ', '.join(map(repr, v.keys()))
184                 raise TypeError(f'unexpected keyword argument{plural}: {keys}')
185 
186             @validator(V_POSITIONAL_ONLY_NAME, check_fields=False, allow_reuse=True)
187             def check_positional_only(cls, v: List[str]) -> None:
188                 plural = '' if len(v) == 1 else 's'
189                 keys = ', '.join(map(repr, v))
190                 raise TypeError(f'positional-only argument{plural} passed as keyword argument{plural}: {keys}')
191 
192             class Config:
193                 extra = Extra.forbid
194 
195         self.model = create_model(to_camel(self.raw_function.__name__), __base__=DecoratorBaseModel, **fields)
196
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pydantic/decorator.py b/pydantic/decorator.py
--- a/pydantic/decorator.py
+++ b/pydantic/decorator.py
@@ -1,4 +1,4 @@
-from functools import update_wrapper
+from functools import wraps
 from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Tuple, TypeVar, cast, get_type_hints
 
 from . import validator
@@ -19,8 +19,15 @@
     Decorator to validate the arguments passed to a function.
     """
     vd = ValidatedFunction(function)
-    vd = update_wrapper(vd, function)  # type: ignore
-    return cast('Callable', vd)
+
+    @wraps(function)
+    def wrapper_function(*args: Any, **kwargs: Any) -> Any:
+        return vd.call(*args, **kwargs)
+
+    wrapper_function.vd = vd  # type: ignore
+    wrapper_function.raw_function = vd.raw_function  # type: ignore
+    wrapper_function.model = vd.model  # type: ignore
+    return cast('Callable', wrapper_function)
 
 
 ALT_V_ARGS = 'v__args'
@@ -95,7 +102,7 @@
 
         self.create_model(fields, takes_args, takes_kwargs)
 
-    def __call__(self, *args: Any, **kwargs: Any) -> Any:
+    def call(self, *args: Any, **kwargs: Any) -> Any:
         values = self.build_values(args, kwargs)
         m = self.model(**values)
         return self.execute(m)

{"golden_diff": "diff --git a/pydantic/decorator.py b/pydantic/decorator.py\n--- a/pydantic/decorator.py\n+++ b/pydantic/decorator.py\n@@ -1,4 +1,4 @@\n-from functools import update_wrapper\n+from functools import wraps\n from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Tuple, TypeVar, cast, get_type_hints\n \n from . import validator\n@@ -19,8 +19,15 @@\n     Decorator to validate the arguments passed to a function.\n     \"\"\"\n     vd = ValidatedFunction(function)\n-    vd = update_wrapper(vd, function)  # type: ignore\n-    return cast('Callable', vd)\n+\n+    @wraps(function)\n+    def wrapper_function(*args: Any, **kwargs: Any) -> Any:\n+        return vd.call(*args, **kwargs)\n+\n+    wrapper_function.vd = vd  # type: ignore\n+    wrapper_function.raw_function = vd.raw_function  # type: ignore\n+    wrapper_function.model = vd.model  # type: ignore\n+    return cast('Callable', wrapper_function)\n \n \n ALT_V_ARGS = 'v__args'\n@@ -95,7 +102,7 @@\n \n         self.create_model(fields, takes_args, takes_kwargs)\n \n-    def __call__(self, *args: Any, **kwargs: Any) -> Any:\n+    def call(self, *args: Any, **kwargs: Any) -> Any:\n         values = self.build_values(args, kwargs)\n         m = self.model(**values)\n         return self.execute(m)\n", "issue": "@validate_arguments on instance methods\n# Bug\r\n\r\nHello, I tried using the new `@validate_arguments` decorator and it doesn't work when used on instance methods.\r\n\r\nI didn't see it on the ToDo in #1205 and it seems like an oversight, maybe due to the special treatment of `self`.\r\n\r\nOutput of `python -c \"import pydantic.utils; print(pydantic.utils.version_info())\"`:\r\n```\r\n$ python3 -c \"import pydantic.utils; print(pydantic.utils.version_info())\"\r\n             pydantic version: 1.4a1\r\n            pydantic compiled: False\r\n                 install path: /home/[user]/git/pydantic/pydantic\r\n               python version: 3.7.5 (default, Nov 20 2019, 09:21:52)  [GCC 9.2.1 20191008]\r\n                     platform: Linux-5.3.0-29-generic-x86_64-with-Ubuntu-19.10-eoan\r\n     optional deps. installed: []\r\n```\r\n\r\n\r\n```py\r\nfrom pydantic import validate_arguments\r\n\r\n\r\nclass SomeObject:\r\n    @validate_arguments\r\n    def some_function(self, i: int):\r\n        print(type(self), self)\r\n        print(type(i), i)\r\n\r\no = SomeObject()\r\no.some_function(1)  # doesn't work, instead of `i` `self` becomes 1\r\n#pydantic.error_wrappers.ValidationError: 1 validation error for SomeFunction\r\n#i\r\n#  field required (type=value_error.missing)\r\n\r\no.some_function(o, 1)  # works, but not the way instance methods are meant to be used\r\n#<class '__main__.SomeObject'> <__main__.SomeObject object at 0x7f32911af3d0>\r\n#<class 'int'> 1\r\n```\n", "before_files": [{"content": "from functools import update_wrapper\nfrom typing import TYPE_CHECKING, Any, Dict, List, Mapping, Tuple, TypeVar, cast, get_type_hints\n\nfrom . import validator\nfrom .errors import ConfigError\nfrom .main import BaseModel, Extra, create_model\nfrom .utils import to_camel\n\n__all__ = ('validate_arguments',)\n\nif TYPE_CHECKING:\n    from .typing import AnyCallable\n\n    Callable = TypeVar('Callable', bound=AnyCallable)\n\n\ndef validate_arguments(function: 'Callable') -> 'Callable':\n    \"\"\"\n    Decorator to validate the arguments passed to a function.\n    \"\"\"\n    vd = ValidatedFunction(function)\n    vd = update_wrapper(vd, function)  # type: ignore\n    return cast('Callable', vd)\n\n\nALT_V_ARGS = 'v__args'\nALT_V_KWARGS = 'v__kwargs'\nV_POSITIONAL_ONLY_NAME = 'v__positional_only'\n\n\nclass ValidatedFunction:\n    def __init__(self, function: 'Callable'):\n        from inspect import signature, Parameter\n\n        parameters: Mapping[str, Parameter] = signature(function).parameters\n\n        if parameters.keys() & {ALT_V_ARGS, ALT_V_KWARGS, V_POSITIONAL_ONLY_NAME}:\n            raise ConfigError(\n                f'\"{ALT_V_ARGS}\", \"{ALT_V_KWARGS}\" and \"{V_POSITIONAL_ONLY_NAME}\" are not permitted as argument '\n                f'names when using the \"{validate_arguments.__name__}\" decorator'\n            )\n\n        self.raw_function = function\n        self.arg_mapping: Dict[int, str] = {}\n        self.positional_only_args = set()\n        self.v_args_name = 'args'\n        self.v_kwargs_name = 'kwargs'\n\n        type_hints = get_type_hints(function)\n        takes_args = False\n        takes_kwargs = False\n        fields: Dict[str, Tuple[Any, Any]] = {}\n        for i, (name, p) in enumerate(parameters.items()):\n            if p.annotation == p.empty:\n                annotation = Any\n            else:\n                annotation = type_hints[name]\n\n            default = ... if p.default == p.empty else p.default\n            if p.kind == Parameter.POSITIONAL_ONLY:\n                self.arg_mapping[i] = name\n                fields[name] = annotation, default\n                fields[V_POSITIONAL_ONLY_NAME] = List[str], None\n                self.positional_only_args.add(name)\n            elif p.kind == Parameter.POSITIONAL_OR_KEYWORD:\n                self.arg_mapping[i] = name\n                fields[name] = annotation, default\n            elif p.kind == Parameter.KEYWORD_ONLY:\n                fields[name] = annotation, default\n            elif p.kind == Parameter.VAR_POSITIONAL:\n                self.v_args_name = name\n                fields[name] = Tuple[annotation, ...], None\n                takes_args = True\n            else:\n                assert p.kind == Parameter.VAR_KEYWORD, p.kind\n                self.v_kwargs_name = name\n                fields[name] = Dict[str, annotation], None  # type: ignore\n                takes_kwargs = True\n\n        # these checks avoid a clash between \"args\" and a field with that name\n        if not takes_args and self.v_args_name in fields:\n            self.v_args_name = ALT_V_ARGS\n\n        # same with \"kwargs\"\n        if not takes_kwargs and self.v_kwargs_name in fields:\n            self.v_kwargs_name = ALT_V_KWARGS\n\n        if not takes_args:\n            # we add the field so validation below can raise the correct exception\n            fields[self.v_args_name] = List[Any], None\n\n        if not takes_kwargs:\n            # same with kwargs\n            fields[self.v_kwargs_name] = Dict[Any, Any], None\n\n        self.create_model(fields, takes_args, takes_kwargs)\n\n    def __call__(self, *args: Any, **kwargs: Any) -> Any:\n        values = self.build_values(args, kwargs)\n        m = self.model(**values)\n        return self.execute(m)\n\n    def build_values(self, args: Tuple[Any, ...], kwargs: Dict[str, Any]) -> Dict[str, Any]:\n        values: Dict[str, Any] = {}\n        if args:\n            arg_iter = enumerate(args)\n            while True:\n                try:\n                    i, a = next(arg_iter)\n                except StopIteration:\n                    break\n                arg_name = self.arg_mapping.get(i)\n                if arg_name is not None:\n                    values[arg_name] = a\n                else:\n                    values[self.v_args_name] = [a] + [a for _, a in arg_iter]\n                    break\n\n        var_kwargs = {}\n        wrong_positional_args = []\n        for k, v in kwargs.items():\n            if k in self.model.__fields__:\n                if k in self.positional_only_args:\n                    wrong_positional_args.append(k)\n                values[k] = v\n            else:\n                var_kwargs[k] = v\n\n        if var_kwargs:\n            values[self.v_kwargs_name] = var_kwargs\n        if wrong_positional_args:\n            values[V_POSITIONAL_ONLY_NAME] = wrong_positional_args\n        return values\n\n    def execute(self, m: BaseModel) -> Any:\n        d = {k: v for k, v in m._iter() if k in m.__fields_set__}\n        kwargs = d.pop(self.v_kwargs_name, None)\n        if kwargs:\n            d.update(kwargs)\n\n        if self.v_args_name in d:\n            args_: List[Any] = []\n            in_kwargs = False\n            kwargs = {}\n            for name, value in d.items():\n                if in_kwargs:\n                    kwargs[name] = value\n                elif name == self.v_args_name:\n                    args_ += value\n                    in_kwargs = True\n                else:\n                    args_.append(value)\n            return self.raw_function(*args_, **kwargs)\n        elif self.positional_only_args:\n            args_ = []\n            kwargs = {}\n            for name, value in d.items():\n                if name in self.positional_only_args:\n                    args_.append(value)\n                else:\n                    kwargs[name] = value\n            return self.raw_function(*args_, **kwargs)\n        else:\n            return self.raw_function(**d)\n\n    def create_model(self, fields: Dict[str, Any], takes_args: bool, takes_kwargs: bool) -> None:\n        pos_args = len(self.arg_mapping)\n\n        class DecoratorBaseModel(BaseModel):\n            @validator(self.v_args_name, check_fields=False, allow_reuse=True)\n            def check_args(cls, v: List[Any]) -> List[Any]:\n                if takes_args:\n                    return v\n\n                raise TypeError(f'{pos_args} positional arguments expected but {pos_args + len(v)} given')\n\n            @validator(self.v_kwargs_name, check_fields=False, allow_reuse=True)\n            def check_kwargs(cls, v: Dict[str, Any]) -> Dict[str, Any]:\n                if takes_kwargs:\n                    return v\n\n                plural = '' if len(v) == 1 else 's'\n                keys = ', '.join(map(repr, v.keys()))\n                raise TypeError(f'unexpected keyword argument{plural}: {keys}')\n\n            @validator(V_POSITIONAL_ONLY_NAME, check_fields=False, allow_reuse=True)\n            def check_positional_only(cls, v: List[str]) -> None:\n                plural = '' if len(v) == 1 else 's'\n                keys = ', '.join(map(repr, v))\n                raise TypeError(f'positional-only argument{plural} passed as keyword argument{plural}: {keys}')\n\n            class Config:\n                extra = Extra.forbid\n\n        self.model = create_model(to_camel(self.raw_function.__name__), __base__=DecoratorBaseModel, **fields)\n", "path": "pydantic/decorator.py"}], "after_files": [{"content": "from functools import wraps\nfrom typing import TYPE_CHECKING, Any, Dict, List, Mapping, Tuple, TypeVar, cast, get_type_hints\n\nfrom . import validator\nfrom .errors import ConfigError\nfrom .main import BaseModel, Extra, create_model\nfrom .utils import to_camel\n\n__all__ = ('validate_arguments',)\n\nif TYPE_CHECKING:\n    from .typing import AnyCallable\n\n    Callable = TypeVar('Callable', bound=AnyCallable)\n\n\ndef validate_arguments(function: 'Callable') -> 'Callable':\n    \"\"\"\n    Decorator to validate the arguments passed to a function.\n    \"\"\"\n    vd = ValidatedFunction(function)\n\n    @wraps(function)\n    def wrapper_function(*args: Any, **kwargs: Any) -> Any:\n        return vd.call(*args, **kwargs)\n\n    wrapper_function.vd = vd  # type: ignore\n    wrapper_function.raw_function = vd.raw_function  # type: ignore\n    wrapper_function.model = vd.model  # type: ignore\n    return cast('Callable', wrapper_function)\n\n\nALT_V_ARGS = 'v__args'\nALT_V_KWARGS = 'v__kwargs'\nV_POSITIONAL_ONLY_NAME = 'v__positional_only'\n\n\nclass ValidatedFunction:\n    def __init__(self, function: 'Callable'):\n        from inspect import signature, Parameter\n\n        parameters: Mapping[str, Parameter] = signature(function).parameters\n\n        if parameters.keys() & {ALT_V_ARGS, ALT_V_KWARGS, V_POSITIONAL_ONLY_NAME}:\n            raise ConfigError(\n                f'\"{ALT_V_ARGS}\", \"{ALT_V_KWARGS}\" and \"{V_POSITIONAL_ONLY_NAME}\" are not permitted as argument '\n                f'names when using the \"{validate_arguments.__name__}\" decorator'\n            )\n\n        self.raw_function = function\n        self.arg_mapping: Dict[int, str] = {}\n        self.positional_only_args = set()\n        self.v_args_name = 'args'\n        self.v_kwargs_name = 'kwargs'\n\n        type_hints = get_type_hints(function)\n        takes_args = False\n        takes_kwargs = False\n        fields: Dict[str, Tuple[Any, Any]] = {}\n        for i, (name, p) in enumerate(parameters.items()):\n            if p.annotation == p.empty:\n                annotation = Any\n            else:\n                annotation = type_hints[name]\n\n            default = ... if p.default == p.empty else p.default\n            if p.kind == Parameter.POSITIONAL_ONLY:\n                self.arg_mapping[i] = name\n                fields[name] = annotation, default\n                fields[V_POSITIONAL_ONLY_NAME] = List[str], None\n                self.positional_only_args.add(name)\n            elif p.kind == Parameter.POSITIONAL_OR_KEYWORD:\n                self.arg_mapping[i] = name\n                fields[name] = annotation, default\n            elif p.kind == Parameter.KEYWORD_ONLY:\n                fields[name] = annotation, default\n            elif p.kind == Parameter.VAR_POSITIONAL:\n                self.v_args_name = name\n                fields[name] = Tuple[annotation, ...], None\n                takes_args = True\n            else:\n                assert p.kind == Parameter.VAR_KEYWORD, p.kind\n                self.v_kwargs_name = name\n                fields[name] = Dict[str, annotation], None  # type: ignore\n                takes_kwargs = True\n\n        # these checks avoid a clash between \"args\" and a field with that name\n        if not takes_args and self.v_args_name in fields:\n            self.v_args_name = ALT_V_ARGS\n\n        # same with \"kwargs\"\n        if not takes_kwargs and self.v_kwargs_name in fields:\n            self.v_kwargs_name = ALT_V_KWARGS\n\n        if not takes_args:\n            # we add the field so validation below can raise the correct exception\n            fields[self.v_args_name] = List[Any], None\n\n        if not takes_kwargs:\n            # same with kwargs\n            fields[self.v_kwargs_name] = Dict[Any, Any], None\n\n        self.create_model(fields, takes_args, takes_kwargs)\n\n    def call(self, *args: Any, **kwargs: Any) -> Any:\n        values = self.build_values(args, kwargs)\n        m = self.model(**values)\n        return self.execute(m)\n\n    def build_values(self, args: Tuple[Any, ...], kwargs: Dict[str, Any]) -> Dict[str, Any]:\n        values: Dict[str, Any] = {}\n        if args:\n            arg_iter = enumerate(args)\n            while True:\n                try:\n                    i, a = next(arg_iter)\n                except StopIteration:\n                    break\n                arg_name = self.arg_mapping.get(i)\n                if arg_name is not None:\n                    values[arg_name] = a\n                else:\n                    values[self.v_args_name] = [a] + [a for _, a in arg_iter]\n                    break\n\n        var_kwargs = {}\n        wrong_positional_args = []\n        for k, v in kwargs.items():\n            if k in self.model.__fields__:\n                if k in self.positional_only_args:\n                    wrong_positional_args.append(k)\n                values[k] = v\n            else:\n                var_kwargs[k] = v\n\n        if var_kwargs:\n            values[self.v_kwargs_name] = var_kwargs\n        if wrong_positional_args:\n            values[V_POSITIONAL_ONLY_NAME] = wrong_positional_args\n        return values\n\n    def execute(self, m: BaseModel) -> Any:\n        d = {k: v for k, v in m._iter() if k in m.__fields_set__}\n        kwargs = d.pop(self.v_kwargs_name, None)\n        if kwargs:\n            d.update(kwargs)\n\n        if self.v_args_name in d:\n            args_: List[Any] = []\n            in_kwargs = False\n            kwargs = {}\n            for name, value in d.items():\n                if in_kwargs:\n                    kwargs[name] = value\n                elif name == self.v_args_name:\n                    args_ += value\n                    in_kwargs = True\n                else:\n                    args_.append(value)\n            return self.raw_function(*args_, **kwargs)\n        elif self.positional_only_args:\n            args_ = []\n            kwargs = {}\n            for name, value in d.items():\n                if name in self.positional_only_args:\n                    args_.append(value)\n                else:\n                    kwargs[name] = value\n            return self.raw_function(*args_, **kwargs)\n        else:\n            return self.raw_function(**d)\n\n    def create_model(self, fields: Dict[str, Any], takes_args: bool, takes_kwargs: bool) -> None:\n        pos_args = len(self.arg_mapping)\n\n        class DecoratorBaseModel(BaseModel):\n            @validator(self.v_args_name, check_fields=False, allow_reuse=True)\n            def check_args(cls, v: List[Any]) -> List[Any]:\n                if takes_args:\n                    return v\n\n                raise TypeError(f'{pos_args} positional arguments expected but {pos_args + len(v)} given')\n\n            @validator(self.v_kwargs_name, check_fields=False, allow_reuse=True)\n            def check_kwargs(cls, v: Dict[str, Any]) -> Dict[str, Any]:\n                if takes_kwargs:\n                    return v\n\n                plural = '' if len(v) == 1 else 's'\n                keys = ', '.join(map(repr, v.keys()))\n                raise TypeError(f'unexpected keyword argument{plural}: {keys}')\n\n            @validator(V_POSITIONAL_ONLY_NAME, check_fields=False, allow_reuse=True)\n            def check_positional_only(cls, v: List[str]) -> None:\n                plural = '' if len(v) == 1 else 's'\n                keys = ', '.join(map(repr, v))\n                raise TypeError(f'positional-only argument{plural} passed as keyword argument{plural}: {keys}')\n\n            class Config:\n                extra = Extra.forbid\n\n        self.model = create_model(to_camel(self.raw_function.__name__), __base__=DecoratorBaseModel, **fields)\n", "path": "pydantic/decorator.py"}]}