Skip to content

Commit b054781

Browse files
committed
Pass parameters by keyword name when inferring sequences.
Close pylint-dev/pylint#2526
1 parent bf344cf commit b054781

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ What's New in astroid 2.1.0?
66
============================
77
Release Date: TBA
88

9+
* Pass parameters by keyword name when inferring sequences.
10+
11+
Close PyCQA/pylint#2526
12+
913
* Correct line numbering for f-strings for complex embedded expressions
1014

1115
When a f-string contained a complex expression, such as an attribute access,

astroid/inference.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ def infer_sequence(self, context=None):
8383
yield self
8484
else:
8585
values = _infer_sequence_helper(self, context)
86-
new_seq = type(self)(self.lineno, self.col_offset, self.parent)
86+
new_seq = type(self)(lineno=self.lineno, col_offset=self.col_offset, parent=self.parent)
8787
new_seq.postinit(values)
88+
8889
yield new_seq
8990

9091

astroid/tests/unittest_inference.py

+11
Original file line numberDiff line numberDiff line change
@@ -4730,5 +4730,16 @@ def foo(self):
47304730
assert inferred[0].value == 2
47314731

47324732

4733+
def test_inferred_sequence_unpacking_works():
4734+
inferred = next(extract_node("""
4735+
def test(*args):
4736+
return (1, *args)
4737+
test(2) #@
4738+
""").infer())
4739+
assert isinstance(inferred, nodes.Tuple)
4740+
assert len(inferred.elts) == 2
4741+
assert [value.value for value in inferred.elts] == [1, 2]
4742+
4743+
47334744
if __name__ == '__main__':
47344745
unittest.main()

0 commit comments

Comments
 (0)