From 5c02dd605146a737735767e63e335d8ff5f091bc Mon Sep 17 00:00:00 2001 From: Andrew Truong <itsandrewtruong@gmail.com> Date: Tue, 5 Nov 2024 23:14:51 -0500 Subject: [PATCH 1/3] test --- pyproject.toml | 1 + tests/trace_server/test_validation.py | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 53baf4ac52a9..10182ec36579 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -167,6 +167,7 @@ select = [ "F401", # https://docs.astral.sh/ruff/rules/unused-import/ "TID252", # https://docs.astral.sh/ruff/rules/relative-imports/#relative-imports-tid252 "UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up + "C409", # https://docs.astral.sh/ruff/rules/unnecessary-literal-within-tuple-call/ ] ignore = [ # we use Google style diff --git a/tests/trace_server/test_validation.py b/tests/trace_server/test_validation.py index 8ab39fb01379..84a80f9b143b 100644 --- a/tests/trace_server/test_validation.py +++ b/tests/trace_server/test_validation.py @@ -42,7 +42,7 @@ def test_validate_purge_req_one(): assert str(e.value) == "Expected value of type <class 'tuple'>, got <class 'dict'>" with pytest.raises(InvalidRequest) as e: - validation.validate_purge_req_one({"eq_": tuple([{"get_field_": "id"}])}) + validation.validate_purge_req_one({"eq_": ({"get_field_": "id"},)}) assert str(e.value) == validation.MESSAGE_INVALID_PURGE with pytest.raises(InvalidRequest) as e: @@ -55,7 +55,7 @@ def test_validate_purge_req_one(): ) validation.validate_purge_req_one( - {"eq_": tuple([{"get_field_": "id"}, {"literal_": "bar"}])} + {"eq_": ({"get_field_": "id"}, {"literal_": "bar"})} ) with pytest.raises(InvalidRequest) as e: @@ -76,22 +76,18 @@ def test_validate_purge_req_one(): validation.validate_purge_req_one( { - "in_": tuple( - [ - {"get_field_": "id"}, - [{"literal_": "foo"}], - ] + "in_": ( + {"get_field_": "id"}, + [{"literal_": "foo"}], ) }, operator="in_", ) validation.validate_purge_req_one( { - "in_": tuple( - [ - {"get_field_": "id"}, - [{"literal_": "bar"}, {"literal_": "foo"}], - ] + "in_": ( + {"get_field_": "id"}, + [{"literal_": "bar"}, {"literal_": "foo"}], ) }, operator="in_", @@ -118,7 +114,7 @@ def test_validate_purge_req_multiple(): validation.validate_purge_req_multiple( [ - {"eq_": tuple([{"get_field_": "id"}, {"literal_": "bar"}])}, - {"eq_": tuple([{"get_field_": "id"}, {"literal_": "bar"}])}, + {"eq_": ({"get_field_": "id"}, {"literal_": "bar"})}, + {"eq_": ({"get_field_": "id"}, {"literal_": "bar"})}, ] ) From 5c447cc91f9edf7061107b45e6cf3002c04bf3df Mon Sep 17 00:00:00 2001 From: Andrew Truong <itsandrewtruong@gmail.com> Date: Tue, 5 Nov 2024 23:16:17 -0500 Subject: [PATCH 2/3] test --- pyproject.toml | 1 + tests/trace/test_weave_client.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 10182ec36579..743b9c5344e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -168,6 +168,7 @@ select = [ "TID252", # https://docs.astral.sh/ruff/rules/relative-imports/#relative-imports-tid252 "UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up "C409", # https://docs.astral.sh/ruff/rules/unnecessary-literal-within-tuple-call/ + "C400", # https://docs.astral.sh/ruff/rules/unnecessary-generator-list/ ] ignore = [ # we use Google style diff --git a/tests/trace/test_weave_client.py b/tests/trace/test_weave_client.py index fe6479df5da7..aa020a0aeace 100644 --- a/tests/trace/test_weave_client.py +++ b/tests/trace/test_weave_client.py @@ -128,7 +128,7 @@ def test_table_update(client): def test_table_append(server): table_ref = server.new_table([1, 2, 3]) new_table_ref, item_id = server.table_append(table_ref, 4) - assert list(r.val for r in server.table_query(new_table_ref)) == [1, 2, 3, 4] + assert [r.val for r in server.table_query(new_table_ref)] == [1, 2, 3, 4] @pytest.mark.skip() @@ -137,7 +137,7 @@ def test_table_remove(server): table_ref1, item_id2 = server.table_append(table_ref0, 2) table_ref2, item_id3 = server.table_append(table_ref1, 3) table_ref3 = server.table_remove(table_ref2, item_id2) - assert list(r.val for r in server.table_query(table_ref3)) == [1, 3] + assert [r.val for r in server.table_query(table_ref3)] == [1, 3] @pytest.mark.skip() @@ -153,7 +153,7 @@ def test_new_val_with_list(server): table_ref = server_val["a"] assert isinstance(table_ref, chobj.TableRef) table_val = server.table_query(table_ref) - assert list(r.val for r in table_val) == [1, 2, 3] + assert [r.val for r in table_val] == [1, 2, 3] @pytest.mark.skip() From 49885a6d5460e2318f32bc6cd82273e09a97ae04 Mon Sep 17 00:00:00 2001 From: Andrew Truong <itsandrewtruong@gmail.com> Date: Tue, 5 Nov 2024 23:18:49 -0500 Subject: [PATCH 3/3] test --- examples/weaveflow/get_started.ipynb | 2 +- pyproject.toml | 1 + tests/trace/test_client_trace.py | 6 +++--- tests/trace/test_objs_query.py | 14 +++++++------- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/examples/weaveflow/get_started.ipynb b/examples/weaveflow/get_started.ipynb index c91c12d65b0d..0bec73b6d846 100644 --- a/examples/weaveflow/get_started.ipynb +++ b/examples/weaveflow/get_started.ipynb @@ -157,7 +157,7 @@ "@weave.op()\n", "def aggregate_scores(score_dicts) -> float:\n", " return sum(\n", - " [score_dict[\"brevity\"] * score_dict[\"relevance\"] for score_dict in score_dicts]\n", + " score_dict[\"brevity\"] * score_dict[\"relevance\"] for score_dict in score_dicts\n", " ) / len(score_dicts)\n", "\n", "\n", diff --git a/pyproject.toml b/pyproject.toml index 743b9c5344e8..fae520d853e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -169,6 +169,7 @@ select = [ "UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up "C409", # https://docs.astral.sh/ruff/rules/unnecessary-literal-within-tuple-call/ "C400", # https://docs.astral.sh/ruff/rules/unnecessary-generator-list/ + "C419", # https://docs.astral.sh/ruff/rules/unnecessary-comprehension-in-call/ ] ignore = [ # we use Google style diff --git a/tests/trace/test_client_trace.py b/tests/trace/test_client_trace.py index 37fc2d49a826..f539700f305c 100644 --- a/tests/trace/test_client_trace.py +++ b/tests/trace/test_client_trace.py @@ -334,7 +334,7 @@ def liner(m: Number, b, x) -> Number: run_calls += num_calls * 3 root_calls += num_calls - total_calls = sum([op_call.num_calls for op_call in result.values()]) + total_calls = sum(op_call.num_calls for op_call in result.values()) return OpCallSpec( call_summaries=result, @@ -409,7 +409,7 @@ def test_trace_call_query_filter_op_version_refs(client): def has_any(list_a: list[str], list_b: list[str]) -> bool: - return any([a in list_b for a in list_a]) + return any(a in list_b for a in list_a) def unique_vals(list_a: list[str]) -> list[str]: @@ -425,7 +425,7 @@ def get_all_calls_asserting_finished( ) ) assert len(res.calls) == call_spec.total_calls - assert all([call.ended_at for call in res.calls]) + assert all(call.ended_at for call in res.calls) return res diff --git a/tests/trace/test_objs_query.py b/tests/trace/test_objs_query.py index 032e440883fc..a69e5a200906 100644 --- a/tests/trace/test_objs_query.py +++ b/tests/trace/test_objs_query.py @@ -30,7 +30,7 @@ def test_objs_query_filter_object_ids(client: WeaveClient): ) ) assert len(res.objs) == 20 - assert all([obj.object_id in ["obj_0", "obj_1"] for obj in res.objs]) + assert all(obj.object_id in ["obj_0", "obj_1"] for obj in res.objs) def test_objs_query_filter_is_op(client: WeaveClient): @@ -60,8 +60,8 @@ def test_objs_query_filter_latest_only(client: WeaveClient): ) ) assert len(res.objs) == 10 - assert all([obj.is_latest for obj in res.objs]) - assert all([obj.val["j"] == 9 for obj in res.objs]) + assert all(obj.is_latest for obj in res.objs) + assert all(obj.val["j"] == 9 for obj in res.objs) def test_objs_query_filter_limit_offset_sort_by_created_at(client: WeaveClient): @@ -77,7 +77,7 @@ def test_objs_query_filter_limit_offset_sort_by_created_at(client: WeaveClient): ) ) assert len(res.objs) == 3 - assert all([obj.is_latest for obj in res.objs]) + assert all(obj.is_latest for obj in res.objs) assert res.objs[0].val["j"] == 9 assert res.objs[0].val["i"] == 4 assert res.objs[1].val["j"] == 9 @@ -95,7 +95,7 @@ def test_objs_query_filter_limit_offset_sort_by_created_at(client: WeaveClient): ) ) assert len(res.objs) == 3 - assert all([obj.is_latest for obj in res.objs]) + assert all(obj.is_latest for obj in res.objs) assert res.objs[0].val["j"] == 9 assert res.objs[0].val["i"] == 5 assert res.objs[1].val["j"] == 9 @@ -117,7 +117,7 @@ def test_objs_query_filter_limit_offset_sort_by_object_id(client: WeaveClient): ) ) assert len(res.objs) == 3 - assert all([obj.is_latest for obj in res.objs]) + assert all(obj.is_latest for obj in res.objs) assert res.objs[0].val["j"] == 9 assert res.objs[0].val["i"] == 4 assert res.objs[1].val["j"] == 9 @@ -135,7 +135,7 @@ def test_objs_query_filter_limit_offset_sort_by_object_id(client: WeaveClient): ) ) assert len(res.objs) == 3 - assert all([obj.is_latest for obj in res.objs]) + assert all(obj.is_latest for obj in res.objs) assert res.objs[0].val["j"] == 9 assert res.objs[0].val["i"] == 5 assert res.objs[1].val["j"] == 9