diff --git a/python/ray/dashboard/modules/reporter/tests/test_reporter.py b/python/ray/dashboard/modules/reporter/tests/test_reporter.py index 7287801c59fb..7c977b0f89b3 100644 --- a/python/ray/dashboard/modules/reporter/tests/test_reporter.py +++ b/python/ray/dashboard/modules/reporter/tests/test_reporter.py @@ -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) diff --git a/python/ray/data/_internal/util.py b/python/ray/data/_internal/util.py index 0a9d975b00c0..81a110c3825f 100644 --- a/python/ray/data/_internal/util.py +++ b/python/ray/data/_internal/util.py @@ -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() @@ -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() diff --git a/python/ray/data/tests/test_image.py b/python/ray/data/tests/test_image.py index ade22cdec35f..7d96159e52f5 100644 --- a/python/ray/data/tests/test_image.py +++ b/python/ray/data/tests/test_image.py @@ -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 @@ -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): diff --git a/python/ray/data/tests/test_operators.py b/python/ray/data/tests/test_operators.py index 153fc38fb7eb..2e3628ce90d7 100644 --- a/python/ray/data/tests/test_operators.py +++ b/python/ray/data/tests/test_operators.py @@ -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() diff --git a/python/ray/data/tests/test_split.py b/python/ray/data/tests/test_split.py index bb91ed8842b1..63a233cd4195 100644 --- a/python/ray/data/tests/test_split.py +++ b/python/ray/data/tests/test_split.py @@ -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 diff --git a/python/ray/serve/_private/deployment_scheduler.py b/python/ray/serve/_private/deployment_scheduler.py index 43a356ec36f5..7fcff9c2d972 100644 --- a/python/ray/serve/_private/deployment_scheduler.py +++ b/python/ray/serve/_private/deployment_scheduler.py @@ -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()) diff --git a/python/ray/serve/tests/test_deploy.py b/python/ray/serve/tests/test_deploy.py index 769bff110093..d54c4a80891b 100644 --- a/python/ray/serve/tests/test_deploy.py +++ b/python/ray/serve/tests/test_deploy.py @@ -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 diff --git a/python/ray/serve/tests/test_grpc.py b/python/ray/serve/tests/test_grpc.py index 7ce7a7e986e2..d36b7512e74a 100644 --- a/python/ray/serve/tests/test_grpc.py +++ b/python/ray/serve/tests/test_grpc.py @@ -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]) diff --git a/python/ray/serve/tests/test_proxy_state.py b/python/ray/serve/tests/test_proxy_state.py index 70dccde7cf95..7216c600176f 100644 --- a/python/ray/serve/tests/test_proxy_state.py +++ b/python/ray/serve/tests/test_proxy_state.py @@ -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 diff --git a/python/ray/serve/tests/test_standalone_3.py b/python/ray/serve/tests/test_standalone_3.py index 13959a59ab33..ac65ee1ca5f1 100644 --- a/python/ray/serve/tests/test_standalone_3.py +++ b/python/ray/serve/tests/test_standalone_3.py @@ -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() ) ) @@ -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() ), ) @@ -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() ), ) diff --git a/python/ray/serve/tests/unit/test_router.py b/python/ray/serve/tests/unit/test_router.py index ddc878b9ba43..63df6c4dd059 100644 --- a/python/ray/serve/tests/unit/test_router.py +++ b/python/ray/serve/tests/unit/test_router.py @@ -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( @@ -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( @@ -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) @@ -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( diff --git a/python/ray/tests/test_failure_3.py b/python/ray/tests/test_failure_3.py index 1e2b3a56da1a..ba89c8399fb8 100644 --- a/python/ray/tests/test_failure_3.py +++ b/python/ray/tests/test_failure_3.py @@ -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, ) @@ -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"] @@ -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, ) diff --git a/python/ray/tests/test_gcs_fault_tolerance.py b/python/ray/tests/test_gcs_fault_tolerance.py index bca9b83021de..544a71143fe8 100644 --- a/python/ray/tests/test_gcs_fault_tolerance.py +++ b/python/ray/tests/test_gcs_fault_tolerance.py @@ -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) diff --git a/python/ray/tests/test_network_failure_e2e.py b/python/ray/tests/test_network_failure_e2e.py index 02e493acbc89..a8504648f217 100644 --- a/python/ray/tests/test_network_failure_e2e.py +++ b/python/ray/tests/test_network_failure_e2e.py @@ -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 @@ -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. diff --git a/python/ray/tests/test_state_api_log.py b/python/ray/tests/test_state_api_log.py index 8e47c4a8d7bc..bb2022564dbf 100644 --- a/python/ray/tests/test_state_api_log.py +++ b/python/ray/tests/test_state_api_log.py @@ -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())) ) diff --git a/python/ray/tests/test_usage_stats.py b/python/ray/tests/test_usage_stats.py index 3cb680eddf0e..fa7570790864 100644 --- a/python/ray/tests/test_usage_stats.py +++ b/python/ray/tests/test_usage_stats.py @@ -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( @@ -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): diff --git a/rllib/utils/replay_buffers/tests/test_prioritized_episode_buffer.py b/rllib/utils/replay_buffers/tests/test_prioritized_episode_buffer.py index facc8dd5b199..c668cbf9a773 100644 --- a/rllib/utils/replay_buffers/tests/test_prioritized_episode_buffer.py +++ b/rllib/utils/replay_buffers/tests/test_prioritized_episode_buffer.py @@ -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)) diff --git a/rllib/utils/tests/test_actor_manager.py b/rllib/utils/tests/test_actor_manager.py index 7056f73632fb..730a5ee78bf3 100644 --- a/rllib/utils/tests/test_actor_manager.py +++ b/rllib/utils/tests/test_actor_manager.py @@ -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() @@ -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()