from enum import Enum, auto
from getpass import getuser
from threading import Thread
-from typing import Any, Callable, Generic, Optional, Self, TypeVar
+from typing import Any, Callable, Generic, NamedTuple, Optional, Self, TypeVar
from uuid import uuid4
# ourselves
from ircplom.events import (
if isinstance(self, _CompletableStringsList):
return self.completed
if isinstance(self, _Topic):
- return self.into_parent()
+ return Topic(*self.completed)
for cls in [cls for cls in self.__class__.__mro__
if AutoAttrMixin not in cls.__mro__]:
obj = cls()
client_id=self.client_id).kw(e=e)
-_TopicWho = TypeVar('_TopicWho', bound=NickUserHost)
+class Topic(NamedTuple):
+ 'Collects both setter and content of channel topic.'
+ what: str = ''
+ who: Optional[NickUserHost] = None
-class Topic[_TopicWho]:
- 'Encapsulates content and setter of channel topic.'
- _what = ''
- _who: Optional[_TopicWho] = None
+class _Topic:
+ _what: str = ''
+ _who: Optional[NickUserHost] = None
- def __eq__(self, other) -> bool:
- return isinstance(self, Topic) and isinstance(other, Topic)\
- and self.what == other.what\
- and self.who == other.who
-
- def _set_what(self, what: str) -> None:
- pass
-
- def _set_who(self, who: _TopicWho) -> None:
- pass
+ def __init__(self) -> None:
+ self.completed: tuple[str, Optional[NickUserHost]] = ('', None)
@property
def what(self) -> str:
- 'Content of channel topic.'
- return self._what[:]
+ 'Content of topic.'
+ return self._what
@what.setter
def what(self, what: str) -> None:
- self._set_what(what)
+ self._what = what
@property
- def who(self) -> Optional[_TopicWho]:
- 'Setter of channel topic.'
+ def who(self) -> Optional[NickUserHost]:
+ 'Setter of topic.'
return self._who
@who.setter
- def who(self, who: _TopicWho) -> None:
- self._set_who(who)
-
-
-class _Topic(Topic['_NickUserHost']):
-
- def __init__(self) -> None:
- self.completed: tuple[str, Optional['_NickUserHost']] = ('', None)
-
- def _set_what(self, what: str) -> None:
- self._what = what
-
- def _set_who(self, who: '_NickUserHost') -> None:
- self._who = who.copy()
+ def who(self, who: NickUserHost) -> None:
+ copy = _NickUserHost.from_str(str(who))
+ self._who = NickUserHost(copy.nick, copy.user, copy.host)
def complete(self) -> None:
'Declare data collection finished, return full or empty content.'
self.completed = (('', None) if self._who is None
- else (self._what, self._who.copy()))
-
- def into_parent(self) -> Topic:
- 'Transform into as presentable as impotent parent class variant.'
- obj = Topic[NickUserHost]()
- obj._what, obj._who = self.completed
- return obj
+ else (self._what, self._who))
class _Channel:
)[-1]
return name + str(0 if not digits else (int(digits) + 1))
- def copy(self) -> Self:
- 'Create indepedentent copy.'
- return self.from_str(str(self))
-
class _UpdatingServerCapability(_UpdatingMixin, ServerCapability):
pass