Multiple values in return statement is prone to error Low

Methods that return multiple values can be difficult to read and prone to error. Return a small class or namedtuple instance instead.

Detector ID
python/multiple-values-in-return@v1.0
Category
Common Weakness Enumeration (CWE) external icon
-

Noncompliant example

1def unpack_multiple_values_noncompliant():
2    # Noncompliant: uses larger number of return values
3    # making it prone to errors.
4    return 'a', 'abc', 100, [0, 1, 2]

Compliant example

1def unpack_multiple_values_compliant():
2    # Compliant: avoids using larger number of return values
3    # making it less prone to errors.
4    return 'abc', 100, [0, 1, 2]