Python

Python

Made by DeepSource

Prefer list.extend(x) over list.append(*x) PY-W0080

Anti-pattern
Major

The append list method only takes one argument. So, if you have a list items, a call like list.append(*items) only works if items has a single element in it. If there is more than one element in items, this code will crash.

Consider using list.extend(items) instead of list.append(*items), as the former is more readable and will not crash when items contains multiple elements.

Bad practice

trees = ['Mango', 'Cedar']
favorite_tree = ['Oak']

trees.append(*favorite_tree)  # `append` is error-prone.

Recommended

trees = ['Mango', 'Cedar']
favorite_tree = ['Oak']

trees.extend(favorite_tree)  # Prefer `extend`.