summaryrefslogtreecommitdiff
path: root/astroid
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2019-07-09 11:08:27 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2019-07-09 13:05:42 +0300
commitf4f205e066f26c8fd7ccfaa1f1719f5f518cc588 (patch)
tree85bf9dfe17d255a125be148f3f2e7bde24493348 /astroid
parent50d53bc61a02e38a0cb272b6d6918741806d1407 (diff)
downloadastroid-git-f4f205e066f26c8fd7ccfaa1f1719f5f518cc588.tar.gz
Build FunctionDef.__get__ to use positional only arguments when inferring the bound method
Diffstat (limited to 'astroid')
-rw-r--r--astroid/interpreter/objectmodel.py12
-rw-r--r--astroid/tests/unittest_object_model.py14
2 files changed, 20 insertions, 6 deletions
diff --git a/astroid/interpreter/objectmodel.py b/astroid/interpreter/objectmodel.py
index 34f65279..cc4a2ba4 100644
--- a/astroid/interpreter/objectmodel.py
+++ b/astroid/interpreter/objectmodel.py
@@ -293,7 +293,7 @@ class FunctionModel(ObjectModel):
return 0
def infer_call_result(self, caller, context=None):
- if len(caller.args) != 2:
+ if len(caller.args) > 2 or len(caller.args) < 1:
raise exceptions.InferenceError(
"Invalid arguments for descriptor binding",
target=self,
@@ -343,11 +343,15 @@ class FunctionModel(ObjectModel):
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"))
+ positional_or_keyword_params = func.args.args.copy()
+ positional_or_keyword_params.append(astroid.AssignName(name="type"))
+
+ positional_only_params = func.args.posonlyargs.copy()
+
arguments = astroid.Arguments(parent=func.args.parent)
arguments.postinit(
- args=params,
+ args=positional_or_keyword_params,
+ posonlyargs=positional_only_params,
defaults=[],
kwonlyargs=[],
kw_defaults=[],
diff --git a/astroid/tests/unittest_object_model.py b/astroid/tests/unittest_object_model.py
index 0cacf20d..ac42485a 100644
--- a/astroid/tests/unittest_object_model.py
+++ b/astroid/tests/unittest_object_model.py
@@ -13,7 +13,7 @@ import xml
import pytest
import astroid
-from astroid import builder
+from astroid import builder, util
from astroid import exceptions
from astroid import MANAGER
from astroid import test_utils
@@ -343,6 +343,17 @@ class FunctionModelTest(unittest.TestCase):
self.assertEqual(len(args), 2)
self.assertEqual([arg.name for arg in args], ["self", "type"])
+ @test_utils.require_version(minver="3.8")
+ def test__get__and_positional_only_args(self):
+ node = builder.extract_node(
+ """
+ def test(self, a, b, /, c): return a + b + c
+ test.__get__(test)(1, 2, 3)
+ """
+ )
+ inferred = next(node.infer())
+ assert inferred is util.Uninferable
+
@unittest.expectedFailure
def test_descriptor_not_inferrring_self(self):
# We can't infer __get__(X, Y)() when the bounded function
@@ -366,7 +377,6 @@ class FunctionModelTest(unittest.TestCase):
class A: pass
def test(self): return 42
test.__get__()() #@
- test.__get__(1)() #@
test.__get__(2, 3, 4) #@
"""
)