summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2018-09-28 14:23:23 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2018-09-28 14:23:23 +0200
commitb054781a7d27bb96e9c620769b5af1e9c58eaaa9 (patch)
tree16c2adb88aee0fd66001416aaf031520af4267e9
parentbf344cf347eba40c4cfa347fcd97d312d29c1fe9 (diff)
downloadastroid-git-b054781a7d27bb96e9c620769b5af1e9c58eaaa9.tar.gz
Pass parameters by keyword name when inferring sequences.
Close PyCQA/pylint#2526
-rw-r--r--ChangeLog4
-rw-r--r--astroid/inference.py3
-rw-r--r--astroid/tests/unittest_inference.py11
3 files changed, 17 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 24610e7d..6089bb4e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,10 @@ What's New in astroid 2.1.0?
============================
Release Date: TBA
+ * Pass parameters by keyword name when inferring sequences.
+
+ Close PyCQA/pylint#2526
+
* Correct line numbering for f-strings for complex embedded expressions
When a f-string contained a complex expression, such as an attribute access,
diff --git a/astroid/inference.py b/astroid/inference.py
index b61427a0..b5403f5b 100644
--- a/astroid/inference.py
+++ b/astroid/inference.py
@@ -83,8 +83,9 @@ def infer_sequence(self, context=None):
yield self
else:
values = _infer_sequence_helper(self, context)
- new_seq = type(self)(self.lineno, self.col_offset, self.parent)
+ new_seq = type(self)(lineno=self.lineno, col_offset=self.col_offset, parent=self.parent)
new_seq.postinit(values)
+
yield new_seq
diff --git a/astroid/tests/unittest_inference.py b/astroid/tests/unittest_inference.py
index 617a62b9..7ecd197d 100644
--- a/astroid/tests/unittest_inference.py
+++ b/astroid/tests/unittest_inference.py
@@ -4730,5 +4730,16 @@ def test_attribute_mro_object_inference():
assert inferred[0].value == 2
+def test_inferred_sequence_unpacking_works():
+ inferred = next(extract_node("""
+ def test(*args):
+ return (1, *args)
+ test(2) #@
+ """).infer())
+ assert isinstance(inferred, nodes.Tuple)
+ assert len(inferred.elts) == 2
+ assert [value.value for value in inferred.elts] == [1, 2]
+
+
if __name__ == '__main__':
unittest.main()