-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
Simplify 'X for X in Y' to 'Y' where applicable #33453
Conversation
@@ -134,7 +134,7 @@ def pytest_print(text): | |||
# It is very unlikely that the user wants to display only numbers, but probably | |||
# the user just wants to count the queries. | |||
exit_stack.enter_context(count_queries(print_fn=pytest_print)) | |||
elif any(c for c in ["time", "trace", "sql", "parameters"]): | |||
elif any(c in columns for c in ["time", "trace", "sql", "parameters"]): |
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
@@ -557,7 +557,7 @@ def test__write_local_data_files_csv_does_not_write_on_empty_rows(self): | |||
with pytest.raises(StopIteration): | |||
next(files)["file_handle"] | |||
|
|||
assert len([f for f in files]) == 0 | |||
assert not list(files) |
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 Y
to bareY
, or convert it tolist()
orset()
oriter()
if needed.