Skip to content
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

[CI] fix flake8 C419 #48189

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def _generate_worker_key(self, proc):
children_pids = {p.pid for p in children}
workers = ReporterAgent._get_workers(obj)
# In the first run, the percent should be 0.
assert all([worker["cpu_percent"] == 0.0 for worker in workers])
assert all(worker["cpu_percent"] == 0.0 for worker in workers)
for _ in range(10):
time.sleep(0.1)
workers = ReporterAgent._get_workers(obj)
Expand Down
8 changes: 2 additions & 6 deletions python/ray/data/_internal/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,9 +972,7 @@ def call_with_retry(
try:
return f()
except Exception as e:
is_retryable = match is None or any(
[pattern in str(e) for pattern in match]
)
is_retryable = match is None or any(pattern in str(e) for pattern in match)
if is_retryable and i + 1 < max_attempts:
# Retry with binary expoential backoff with random jitter.
backoff = min((2 ** (i + 1)), max_backoff_s) * random.random()
Expand Down Expand Up @@ -1023,9 +1021,7 @@ def iterate_with_retry(
yield item
return
except Exception as e:
is_retryable = match is None or any(
[pattern in str(e) for pattern in match]
)
is_retryable = match is None or any(pattern in str(e) for pattern in match)
if is_retryable and i + 1 < max_attempts:
# Retry with binary expoential backoff with random jitter.
backoff = min((2 ** (i + 1)), max_backoff_s) * random.random()
Expand Down
4 changes: 2 additions & 2 deletions python/ray/data/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_mode(
):
# "different-modes" contains 32x32 images with modes "CMYK", "L", and "RGB"
ds = ray.data.read_images("example://image-datasets/different-modes", mode=mode)
assert all([record["image"].shape == expected_shape for record in ds.take()])
assert all(record["image"].shape == expected_shape for record in ds.take())

def test_partitioning(
self, ray_start_regular_shared, enable_automatic_tensor_extension_cast
Expand Down Expand Up @@ -178,7 +178,7 @@ def test_random_shuffle(self, ray_start_regular_shared, restore_data_context):
assert not all(all_paths_matched)
# Check all files are output properly without missing one.
assert all(
[file_paths == sorted(output_paths) for output_paths in output_paths_list]
file_paths == sorted(output_paths) for output_paths in output_paths_list
)

def test_e2e_prediction(self, shutdown_only):
Expand Down
2 changes: 1 addition & 1 deletion python/ray/data/tests/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ def test_union_operator(ray_start_regular_shared, preserve_order):
assert union_op.get_next() == data2[0]
assert union_op.get_next() == data1[1]

assert all([len(b) == 0 for b in union_op._input_buffers])
assert all(len(b) == 0 for b in union_op._input_buffers)

_take_outputs(union_op)
union_op.all_inputs_done()
Expand Down
2 changes: 1 addition & 1 deletion python/ray/data/tests/test_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def _test_equal_split_balanced(block_sizes, num_splits):
assert len(split_counts) == num_splits
expected_block_size = total_rows // num_splits
# Check that all splits are the expected size.
assert all([count == expected_block_size for count in split_counts])
assert all(count == expected_block_size for count in split_counts)
expected_total_rows = sum(split_counts)
# Check that the expected number of rows were dropped.
assert total_rows - expected_total_rows == total_rows % num_splits
Expand Down
2 changes: 1 addition & 1 deletion python/ray/serve/_private/deployment_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def can_fit(self, other):

def __eq__(self, other):
keys = set(self.keys()) | set(other.keys())
return all([self.get(k) == other.get(k) for k in keys])
return all(self.get(k) == other.get(k) for k in keys)

def __add__(self, other):
keys = set(self.keys()) | set(other.keys())
Expand Down
2 changes: 1 addition & 1 deletion python/ray/serve/tests/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def reconfigure():
signal.send.remote()
ray.get(reconfigure_ref)

assert all([r.result() == 1 for r in responses])
assert all(r.result() == 1 for r in responses)
assert handle.remote().result() == 2


Expand Down
2 changes: 1 addition & 1 deletion python/ray/serve/tests/test_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def Streaming(
assert error_message == rpc_error.details()
assert trailing_metadata in rpc_error.trailing_metadata()
# request_id should always be set in the trailing metadata.
assert any([key == "request_id" for key, _ in rpc_error.trailing_metadata()])
assert any(key == "request_id" for key, _ in rpc_error.trailing_metadata())


@pytest.mark.parametrize("streaming", [False, True])
Expand Down
6 changes: 2 additions & 4 deletions python/ray/serve/tests/test_proxy_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,8 @@ def _update_and_check_proxy_state_manager(
proxy_state_manager.update(**kwargs)
proxy_states = proxy_state_manager._proxy_states
assert all(
[
proxy_states[node_ids[idx]].status == statuses[idx]
for idx in range(len(node_ids))
]
proxy_states[node_ids[idx]].status == statuses[idx]
for idx in range(len(node_ids))
), [proxy_state.status for proxy_state in proxy_states.values()]
return True

Expand Down
6 changes: 3 additions & 3 deletions python/ray/serve/tests/test_standalone_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def __call__(self):
# Ensure the all resources are shutdown.
wait_for_condition(
lambda: all(
[actor["State"] == "DEAD" for actor in ray._private.state.actors().values()]
actor["State"] == "DEAD" for actor in ray._private.state.actors().values()
)
)

Expand Down Expand Up @@ -520,7 +520,7 @@ def __call__(self):
# Ensure the all resources are shutdown gracefully.
wait_for_condition(
lambda: all(
[actor["State"] == "DEAD" for actor in ray._private.state.actors().values()]
actor["State"] == "DEAD" for actor in ray._private.state.actors().values()
),
)

Expand Down Expand Up @@ -553,7 +553,7 @@ def __call__(self):
# Ensure the all resources are shutdown gracefully.
wait_for_condition(
lambda: all(
[actor["State"] == "DEAD" for actor in ray._private.state.actors().values()]
actor["State"] == "DEAD" for actor in ray._private.state.actors().values()
),
)

Expand Down
32 changes: 12 additions & 20 deletions python/ray/serve/tests/unit/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,9 @@ async def test_max_queued_requests_no_limit(
# Unblock the requests, now they should all get scheduled.
fake_replica_scheduler.unblock_requests(100)
assert all(
[
not replica_result._is_generator_object
and replica_result._replica_id == r1_id
for replica_result in await asyncio.gather(*assign_request_tasks)
]
not replica_result._is_generator_object
and replica_result._replica_id == r1_id
for replica_result in await asyncio.gather(*assign_request_tasks)
)

async def test_max_queued_requests_limited(
Expand Down Expand Up @@ -467,11 +465,9 @@ async def test_max_queued_requests_limited(
# Unblock the requests, now they should all get scheduled.
fake_replica_scheduler.unblock_requests(5)
assert all(
[
not replica_result._is_generator_object
and replica_result._replica_id == r1_id
for replica_result in await asyncio.gather(*assign_request_tasks)
]
not replica_result._is_generator_object
and replica_result._replica_id == r1_id
for replica_result in await asyncio.gather(*assign_request_tasks)
)

async def test_max_queued_requests_updated(
Expand Down Expand Up @@ -539,11 +535,9 @@ async def test_max_queued_requests_updated(
done, pending = await asyncio.wait(assign_request_tasks, timeout=0.01)
assert len(pending) == 5
assert all(
[
not replica_result._is_generator_object
and replica_result._replica_id == r1_id
for replica_result in await asyncio.gather(*done)
]
not replica_result._is_generator_object
and replica_result._replica_id == r1_id
for replica_result in await asyncio.gather(*done)
)
assign_request_tasks = list(pending)

Expand All @@ -556,11 +550,9 @@ async def test_max_queued_requests_updated(
# Unblock the requests, now they should all get scheduled.
fake_replica_scheduler.unblock_requests(5)
assert all(
[
not replica_result._is_generator_object
and replica_result._replica_id == r1_id
for replica_result in await asyncio.gather(*assign_request_tasks)
]
not replica_result._is_generator_object
and replica_result._replica_id == r1_id
for replica_result in await asyncio.gather(*assign_request_tasks)
)

@pytest.mark.parametrize(
Expand Down
8 changes: 4 additions & 4 deletions python/ray/tests/test_failure_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,12 @@ def task():

# Validate all children of the worker processes are in a sleeping state.
processes = [psutil.Process(pid) for pid in pids]
assert all([proc.status() == psutil.STATUS_SLEEPING for proc in processes])
assert all(proc.status() == psutil.STATUS_SLEEPING for proc in processes)

# Valdiate children of worker process die after SIGINT.
driver_proc.send_signal(signal.SIGINT)
wait_for_condition(
condition_predictor=lambda: all([not proc.is_running() for proc in processes]),
condition_predictor=lambda: all(not proc.is_running() for proc in processes),
timeout=30,
)

Expand Down Expand Up @@ -543,7 +543,7 @@ def leaker_task(index):

# Validate all children of the worker processes are in a sleeping state.
processes = [psutil.Process(pid) for pid in pids]
assert all([proc.status() == psutil.STATUS_SLEEPING for proc in processes])
assert all(proc.status() == psutil.STATUS_SLEEPING for proc in processes)

# Obtain psutil handle for raylet process
raylet_proc = [p for p in psutil.process_iter() if p.name() == "raylet"]
Expand All @@ -556,7 +556,7 @@ def leaker_task(index):

print("Waiting for child procs to die")
wait_for_condition(
condition_predictor=lambda: all([not proc.is_running() for proc in processes]),
condition_predictor=lambda: all(not proc.is_running() for proc in processes),
timeout=30,
)

Expand Down
2 changes: 1 addition & 1 deletion python/ray/tests/test_gcs_fault_tolerance.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ def pid(self):

# Wait until all data is updated in the replica
leader_cli.set("_hole", "0")
wait_for_condition(lambda: all([b"_hole" in f.keys("*") for f in follower_cli]))
wait_for_condition(lambda: all(b"_hole" in f.keys("*") for f in follower_cli))

# Now kill pid
leader_process = psutil.Process(pid=leader_pid)
Expand Down
4 changes: 2 additions & 2 deletions python/ray/tests/test_network_failure_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def check_task_running(n=None):
print("tasks_json:", json.dumps(tasks_json, indent=2))
if n is not None and n != len(tasks_json):
return False
return all([task["state"] == "RUNNING" for task in tasks_json])
return all(task["state"] == "RUNNING" for task in tasks_json)
return False

# list_task make sure all tasks are running
Expand Down Expand Up @@ -102,7 +102,7 @@ def check_task_not_running():
if output.exit_code == 0:
tasks_json = json.loads(output.output)
print("tasks_json:", json.dumps(tasks_json, indent=2))
return all([task["state"] != "RUNNING" for task in tasks_json])
return all(task["state"] != "RUNNING" for task in tasks_json)
return False

# we set num_cpus=0 for head node.
Expand Down
2 changes: 1 addition & 1 deletion python/ray/tests/test_state_api_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ def verify_worker_logs():
"worker_out",
"worker_err",
]
assert all([cat in logs for cat in worker_log_categories])
assert all(cat in logs for cat in worker_log_categories)
num_workers = len(
list(filter(lambda w: w["worker_type"] == "WORKER", list_workers()))
)
Expand Down
6 changes: 3 additions & 3 deletions python/ray/tests/test_usage_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ def test_usage_report_disabled_ray_init_cluster(
contents = f.readlines()
break
assert contents is not None
assert any(["Usage reporting is disabled" in c for c in contents])
assert any("Usage reporting is disabled" in c for c in contents)


def test_usage_report_disabled(
Expand Down Expand Up @@ -1369,8 +1369,8 @@ def test_usage_report_disabled(
contents = f.readlines()
break
assert contents is not None
assert any(["Usage reporting is disabled" in c for c in contents])
assert all(["Usage report request failed" not in c for c in contents])
assert any("Usage reporting is disabled" in c for c in contents)
assert all("Usage report request failed" not in c for c in contents)


def test_usage_file_error_message(monkeypatch, ray_start_cluster, reset_usage_stats):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,7 @@ def test_update_priorities(self):
sample = buffer.sample(batch_size_B=16, n_step=1)

index_counts.append(
any(
[
idx in last_sampled_indices
for idx in buffer._last_sampled_indices
]
)
any(idx in last_sampled_indices for idx in buffer._last_sampled_indices)
)

self.assertGreater(0.15, sum(index_counts) / len(index_counts))
Expand Down
4 changes: 2 additions & 2 deletions rllib/utils/tests/test_actor_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def test_sync_call_not_ignore_error(self):
wait_for_restore()

# Some calls did error out.
self.assertTrue(any([not r.ok for r in results]))
self.assertTrue(any(not r.ok for r in results))

manager.clear()

Expand All @@ -248,7 +248,7 @@ def test_sync_call_not_bringing_back_actors(self):

results = manager.foreach_actor(lambda w: w.call())
# Some calls did error out.
self.assertTrue(any([not r.ok for r in results]))
self.assertTrue(any(not r.ok for r in results))

# Wait for actors to recover.
wait_for_restore()
Expand Down