rspec/rules/S6465/python/rule.adoc

21 lines
531 B
Plaintext
Raw Normal View History

Unpacking lets developers assign values of an iterable simultaneously to different targets in a single assignment.
However, for this assignment to work, the iterable should have the same number of elements as there are targets in the target list.
If this is not respected, a `ValueError` will be produced at runtime.
== Noncompliant Code Example
[source,python]
----
def foo(param):
ls = [1, 2, 3]
x, y = ls # Noncompliant
----
== Compliant Solution
[source,python]
----
def foo(param):
ls = [1, 2, 3]
x, y, z = ls
----