-
-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
style: Fix unnecessary-comprehension (C416) #4453
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not build and tested, but the changes are according to the ruff rule. In some cases I am not sure if the list()
is even necessary...
I also researched a bit on the behavior as I thought it helped with copies and the likes. It seems it doesn't help, and is no more different as a shallow copy either. So the list constructor provides the same as the comprehension, only that the list comprehensions are not the fastest. It was harder to find real definitive answers that weren't related to Python 2 era. So, in order to at least have the same behavior, in case there were some edge cases when there wasn't a list (ie, we wouldn't want to have a string not as a list element, as iterating it would go character-per-character instead), using the list constructor seems the best approach. |
There was a recursion problem here since |
Ruff rule: https://docs.astral.sh/ruff/rules/unnecessary-comprehension/