Skip to content

Commit

Permalink
Fix crash on unbalanced tuple unpacking
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored and Pierre-Sassoulas committed Mar 29, 2022
1 parent 2066cab commit 19e6531
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ What's New in Pylint 2.13.3?
============================
Release date: TBA

* Fix crash involving unbalanced tuple unpacking.

Closes #5998


What's New in Pylint 2.13.2?
Expand Down
2 changes: 2 additions & 0 deletions pylint/checkers/base/name_checker/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ def visit_assignname(self, node: nodes.AssignName) -> None:
elif (
isinstance(node.parent, nodes.Tuple)
and isinstance(assign_type.value, nodes.Tuple)
# protect against unbalanced tuple unpacking
and node.parent.elts.index(node) < len(assign_type.value.elts)
and self._assigns_typevar(
assign_type.value.elts[node.parent.elts.index(node)]
)
Expand Down
3 changes: 3 additions & 0 deletions tests/functional/u/unbalanced_tuple_unpacking.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,6 @@ def my_function(mystring):
a, b = my_function("12") # [unbalanced-tuple-unpacking]
c = my_function("12")
d, *_ = my_function("12")

# https://github.com/PyCQA/pylint/issues/5998
x, y, z = (1, 2) # [unbalanced-tuple-unpacking]
1 change: 1 addition & 0 deletions tests/functional/u/unbalanced_tuple_unpacking.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ unbalanced-tuple-unpacking:96:8:96:33:UnbalancedUnpacking.test:"Possible unbalan
unbalanced-tuple-unpacking:140:8:140:43:MyClass.sum_unpack_3_into_4:"Possible unbalanced tuple unpacking with sequence defined at line 128: left side has 4 label(s), right side has 3 value(s)":UNDEFINED
unbalanced-tuple-unpacking:145:8:145:28:MyClass.sum_unpack_3_into_2:"Possible unbalanced tuple unpacking with sequence defined at line 128: left side has 2 label(s), right side has 3 value(s)":UNDEFINED
unbalanced-tuple-unpacking:157:0:157:24::"Possible unbalanced tuple unpacking with sequence defined at line 151: left side has 2 label(s), right side has 0 value(s)":UNDEFINED
unbalanced-tuple-unpacking:162:0:162:16::"Possible unbalanced tuple unpacking with sequence (1, 2): left side has 3 label(s), right side has 2 value(s)":UNDEFINED

0 comments on commit 19e6531

Please sign in to comment.