home · contact · privacy
Simplify CompletableTopic.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 11 Sep 2025 20:20:27 +0000 (22:20 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 11 Sep 2025 20:20:27 +0000 (22:20 +0200)
ircplom/client.py
ircplom/client_tui.py

index b404218d2cf33fafc4efbca98a76aa031110bfef..bd6ad5bf38d1883a347eb87b052cac28c41074af 100644 (file)
@@ -7,7 +7,7 @@ from enum import Enum, auto
 from getpass import getuser
 from threading import Thread
 from typing import (Any, Callable, Collection, Generic, Iterable, Iterator,
-                    NamedTuple, Optional, Self, Set, TypeVar)
+                    Optional, Self, Set, TypeVar)
 from uuid import uuid4
 # ourselves
 from ircplom.events import (
@@ -204,11 +204,9 @@ class IntoEndnodeUpdatesMixin(AutoAttrMixin):
     def into_endnode_updates(self, path: tuple[str, ...]
                              ) -> list[tuple[tuple[str, ...], Any]]:
         'Return path-value pairs for any update-worthy sub-elements.'
-        if isinstance(self, _CompletableStringsCollection):
+        if isinstance(self, _Completable):
             return ([(path, self._completed)] if self._completed is not None
                     else [])
-        if isinstance(self, _CompletableTopic):
-            return [(path, Topic(*self._completed))]
         updates = []
         for key, val in (self._dict.items() if isinstance(self, Dict)
                          else ((k, getattr(self, k))
@@ -326,7 +324,8 @@ class ServerCapability:
     enabled: bool = False
 
 
-class Topic(NamedTuple):
+@dataclass
+class Topic:
     'Collects both setter and content of channel topic.'
     what: str = ''
     who: Optional[NickUserHost] = None
@@ -376,35 +375,14 @@ class _IrcConnection(BaseIrcConnection, _ClientIdMixin):
                                     client_id=self.client_id).kw(e=e)
 
 
-class _CompletableTopic(_Completable):
-    _what: str = ''
-    _who: Optional[NickUserHost] = None
-
-    def __init__(self) -> None:
-        self._completed: tuple[str, Optional[NickUserHost]] = ('', None)
-
-    @property
-    def what(self) -> str:
-        'Content of topic.'
-        return self._what
-
-    @what.setter
-    def what(self, what: str) -> None:
-        self._what = what
-
-    @property
-    def who(self) -> Optional[NickUserHost]:
-        'Setter of topic.'
-        return self._who
-
-    @who.setter
-    def who(self, who: NickUserHost) -> None:
-        copy = _NickUserHost.from_str(str(who))
-        self._who = NickUserHost(copy.nick, copy.user, copy.host)
+class _CompletableTopic(_Completable, Topic):
+    _completed: Optional[Topic] = None
 
     def complete(self) -> None:
-        self._completed = (('', None) if self._who is None
-                           else (self._what, self._who))
+        assert self.who is not None
+        copy = _NickUserHost.from_str(str(self.who))
+        self._completed = Topic(self.what,
+                                NickUserHost(copy.nick, copy.user, copy.host))
 
 
 class _Channel:
index 1a96377c07f1cb836fb5a97fbb34930ed135124a..f1d5e90431802eddf87bc24d67710d75d8876296 100644 (file)
@@ -217,7 +217,7 @@ class _QueryWindow(_ChatWindow):
 
 class _UpdatingChannel(_UpdatingNode):
     user_ids: set[str]
-    topic: Topic = Topic()
+    topic: Topic
     log_scopes = {'': LogScope.CHAT}
 
     def _focused_set_and_report_change(