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

feat: Allows field_ref to be used as a key value in FieldSet #1756

Merged
merged 6 commits into from
Dec 7, 2023
Merged
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
1 change: 1 addition & 0 deletions changes/1756.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In order to be able to use not only alt_name but also field_ref when using the --format option of session list, add values to FieldSet.
4 changes: 3 additions & 1 deletion src/ai/backend/client/output/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ def _default_formatter(self) -> AbstractOutputFormatter:

class FieldSet(UserDict, Mapping[str, FieldSpec]):
def __init__(self, fields: Sequence[FieldSpec]) -> None:
super().__init__({f.alt_name: f for f in fields})
fields_set = {f.alt_name: f for f in fields}
fields_set.update({f.field_ref: fields_set[f.alt_name] for f in fields})
super().__init__(fields_set)


T = TypeVar("T")
Expand Down
4 changes: 2 additions & 2 deletions tests/client/output/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_fieldspec_init():
]
),
)
assert f.field_ref == "key_foo { bar baz }"
assert f.field_ref == "key_foo { bar baz baz }"
achimnol marked this conversation as resolved.
Show resolved Hide resolved
assert f.field_name == "key_foo"
assert f.humanized_name == "Key Foo"
assert f.subfields["bar"].field_ref == "bar"
Expand All @@ -65,7 +65,7 @@ def test_fieldspec_init():
]
),
)
assert f.field_ref == "key_foo { bar { kaz } }"
assert f.field_ref == "key_foo { bar { kaz } bar { kaz } }"
assert f.field_name == "key_foo"
assert f.humanized_name == "Key Foo"
assert f.subfields["bar"].field_ref == "bar { kaz }"
Loading