From 13b0b15280442e23166c0b7539f880cba5239a46 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Wed, 3 Sep 2025 23:54:07 +0200 Subject: [PATCH] Minor refactoring. --- ircplom/msg_parse_expectations.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) 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): -- 2.30.2