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

chore(weave): ruff: enable C419 #2908

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion examples/weaveflow/get_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ 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/
"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
Expand Down
6 changes: 3 additions & 3 deletions tests/trace/test_client_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]:
Expand All @@ -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


Expand Down
14 changes: 7 additions & 7 deletions tests/trace/test_objs_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/trace/test_weave_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
24 changes: 10 additions & 14 deletions tests/trace_server/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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_",
Expand All @@ -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"})},
]
)
Loading