_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:
'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):