Skip to content
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
7 changes: 4 additions & 3 deletions fgmetric/collections/_counter_pivot_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ def _get_counter_fieldname(cls) -> str | None:
if len(counter_fieldnames) > 1:
raise TypeError(
"Only one Counter per model is currently supported. "
f"Found multiple fields with Counter types: {', '.join(counter_fieldnames)}"
f"Found multiple Counter fields: {', '.join(counter_fieldnames)}"
)

counter_fieldname: str | None = counter_fieldnames[0] if counter_fieldnames else None

if counter_fieldname:
counter_field_info: FieldInfo = cls.model_fields[counter_fieldname]
if is_optional(counter_field_info.annotation):
raise TypeError(f"Optional Counters are not supported: {counter_fieldname}")
raise TypeError(f"Optional Counter fields are not supported: '{counter_fieldname}'")

return counter_fieldname

Expand Down Expand Up @@ -109,7 +109,8 @@ def _get_counter_enum(cls) -> type[StrEnum] | None: # noqa: C901
enum_cls: type[StrEnum] = args[0]
else:
raise TypeError(
f"Counter fields must have a StrEnum type parameter: {cls._counter_fieldname}"
f"Counter fields must have a StrEnum type parameter,"
f" got {info.annotation} for field '{cls._counter_fieldname}'"
)

return enum_cls
Expand Down
3 changes: 2 additions & 1 deletion fgmetric/collections/_delimited_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def _require_single_character_collection_delimiter(cls) -> None:
"""Require collection delimiters to be single characters."""
if len(cls.collection_delimiter) != 1:
raise ValueError(
f"Class collection delimiter must be a single character: {cls.collection_delimiter}"
"collection_delimiter must be a single character,"
f" got: {cls.collection_delimiter!r}"
)

@final
Expand Down
9 changes: 6 additions & 3 deletions tests/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ class FakeMetric(Metric):
name: str
counts: Counter[str]

assert str(excinfo.value) == "Counter fields must have a StrEnum type parameter: counts"
assert str(excinfo.value) == (
"Counter fields must have a StrEnum type parameter,"
" got collections.Counter[str] for field 'counts'"
)


def test_counter_pivot_table_raises_if_multiple_counters() -> None:
Expand All @@ -280,7 +283,7 @@ class FakeMetric(Metric):

assert str(excinfo.value) == (
"Only one Counter per model is currently supported. "
"Found multiple fields with Counter types: foo_counts, bar_counts"
"Found multiple Counter fields: foo_counts, bar_counts"
)


Expand All @@ -296,4 +299,4 @@ class FakeMetric(Metric):
name: str
counts: Counter[FakeEnum] | None

assert str(excinfo.value) == "Optional Counters are not supported: counts"
assert str(excinfo.value) == "Optional Counter fields are not supported: 'counts'"