diff options
| author | Claudiu Popa <pcmanticore@gmail.com> | 2018-06-07 10:18:54 -0700 |
|---|---|---|
| committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-06-07 10:18:54 -0700 |
| commit | c56df76e394626e541039467418e87795f5342ea (patch) | |
| tree | ac132e362f3a8eb44eb28ba9cfe17b9e7e06d3c3 /astroid/interpreter/objectmodel.py | |
| parent | 1891690277a34b01b2a5311676875a631234708e (diff) | |
| download | astroid-git-c56df76e394626e541039467418e87795f5342ea.tar.gz | |
DescriptorBoundMethod has the correct number of arguments defined.
Usually a function that we want to bind to a class has the
following signature:
def test(self):
pass
This function has only the *self* parameter but when we access test.__get__
we get a new object which has two parameters, *self* and *type*.
This change adds the extra parameter in the DescriptorBoundMethod's args
property.
Diffstat (limited to 'astroid/interpreter/objectmodel.py')
| -rw-r--r-- | astroid/interpreter/objectmodel.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/astroid/interpreter/objectmodel.py b/astroid/interpreter/objectmodel.py index 238f69d6..0a838b59 100644 --- a/astroid/interpreter/objectmodel.py +++ b/astroid/interpreter/objectmodel.py @@ -315,6 +315,31 @@ class FunctionModel(ObjectModel): proxy = bases.UnboundMethod(new_func) yield bases.BoundMethod(proxy=proxy, bound=cls) + @property + def args(self): + """Overwrite the underlying args to match those of the underlying func + + Usually the underlying *func* is a function/method, as in: + + def test(self): + pass + + This has only the *self* parameter but when we access test.__get__ + we get a new object which has two parameters, *self* and *type*. + """ + nonlocal func + params = func.args.args.copy() + params.append(astroid.AssignName(name='type')) + arguments = astroid.Arguments(parent=func.args.parent,) + arguments.postinit( + args=params, + defaults=[], + kwonlyargs=[], + kw_defaults=[], + annotations=[], + ) + return arguments + return DescriptorBoundMethod(proxy=self._instance, bound=self._instance) # These are here just for completion. |
