This rule raises an issue when a comprehension is used to only copy a collection. Instead, the respective constructor should be used.

Why is this an issue?

Python comprehensions are a concise way to create new collections while transforming or filtering elements. However, using a comprehension that copies elements from one collection to another without any transformation is less readable than using the respective constructor directly.

Therefore, when a comprehension is only copying elements, use the appropriate constructor instead:

How to fix it

Replace comprehensions that copy elements from one collection to another with the respective constructor.

Code examples

Noncompliant code example

some_list = [1, 2, 3, 2]
[x for x in some_list] # Noncompliant

Compliant solution

some_list = [1, 2, 3, 2]
list(some_list) # Compliant

Resources

Documentation