Skip to content

Commit 276d1b9

Browse files
committed
Simplify ActionGroup label default (#1992)
## Summary - ActionGroup `label` field now defaults to `""` via a `_to_str` converter instead of post-init fixup - Simplifies `__attrs_post_init__` to only handle id/oid resolution Depends on #1991 (model simplifications). ## Breaking changes - `ActionGroup.label` type changed from `str | None` to `str` (always a string, `None` input is converted to `""`) ## Test plan - [ ] ActionGroup tests pass with label=None, label="", and label="value"
1 parent aedb971 commit 276d1b9

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pyoverkiz/models.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ def convert(value: Any) -> Any:
8686
return convert
8787

8888

89+
def _to_str(value: str | None) -> str:
90+
"""Converter: None -> empty string, otherwise passthrough."""
91+
return value or ""
92+
93+
8994
def _flexible_init(cls: type) -> type:
9095
"""Class decorator: make attrs ``__init__`` accept (and ignore) unknown kwargs.
9196
@@ -682,7 +687,7 @@ class ActionGroup:
682687
actions: list[Action] = field(converter=_to_list(Action))
683688
creation_time: int | None = None
684689
last_update_time: int | None = None
685-
label: str | None = field(repr=obfuscate_string, default=None)
690+
label: str = field(repr=obfuscate_string, default="", converter=_to_str)
686691
metadata: str | None = None
687692
shortcut: bool | None = None
688693
notification_type_mask: int | None = None
@@ -693,14 +698,12 @@ class ActionGroup:
693698
id: str | None = field(repr=obfuscate_id, default=None)
694699

695700
def __attrs_post_init__(self) -> None:
696-
"""Resolve id/oid fallback and ensure label is never None."""
701+
"""Resolve id/oid fallback."""
697702
if self.oid is None and self.id is None:
698703
raise ValueError("Either 'oid' or 'id' must be provided")
699704
resolved = cast(str, self.oid or self.id)
700705
self.id = resolved
701706
self.oid = resolved
702-
if self.label is None:
703-
self.label = ""
704707

705708

706709
@_flexible_init

0 commit comments

Comments
 (0)