From: Christian Heller <c.heller@plomlompom.de> Date: Wed, 3 Sep 2025 21:54:07 +0000 (+0200) Subject: Minor refactoring. X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/%7B%7Bprefix%7D%7D/process?a=commitdiff_plain;h=HEAD;p=ircplom Minor refactoring. --- diff --git a/ircplom/msg_parse_expectations.py b/ircplom/msg_parse_expectations.py index 93ad0be..de9f488 100644 --- a/ircplom/msg_parse_expectations.py +++ b/ircplom/msg_parse_expectations.py @@ -18,20 +18,15 @@ class _MsgTok(Enum): _MsgTokGuide = str | _MsgTok | tuple[str | _MsgTok, str] -class _Command: +class _Command(NamedTuple): + verb: str + path: tuple[str, ...] - def __init__(self, input_: str) -> None: - self.verb, path_str = input_.split('_', maxsplit=1) - self.path = tuple(path_str.split('.')) - - def __str__(self) -> str: - return f'{self.verb}_{".".join(self.path)}' - - def __hash__(self) -> int: - return hash(str(self)) - - def __eq__(self, other) -> bool: - return hash(self) == hash(other) + @classmethod + def from_(cls, input_: str) -> Self: + 'Split by first "_" into verb, path (split into steps tuple by ".").' + verb, path_str = input_.split('_', maxsplit=1) + return cls(verb, tuple(path_str.split('.'))) class _MsgParseExpectation: @@ -53,7 +48,7 @@ class _MsgParseExpectation: 'Split by ":" into commands (further split by ","), title.' toks = input_.split(':', maxsplit=1) title = toks[1] - commands = [_Command(t) for t in toks[0].split(',') if t] + commands = [_Command.from_(t) for t in toks[0].split(',') if t] return cls(title, tuple(commands)) class _TokExpectation(NamedTuple):