-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Simplify 'X for X in Y' to 'Y' where applicable #33453
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
Conversation
tests/conftest.py
Outdated
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.
Nice catch
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.
| assert not list(files) | |
| with pytest.raises(StopIteration): | |
| next(files) |
Alternative approach. Shouldn’t be too much difference in practice (especially in a test).
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.
This is really elegant. Anyway, since the previous block already expects a StopIteration, we do not have to repeat it here. I'll remove it altogether.
(cherry picked from commit 7700fb1)
Simplify loops without condition
X for X in Yto bareY, or convert it tolist()orset()oriter()if needed.