home · contact · privacy
Structure .clear ability into proper interface.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 11 Sep 2025 13:34:09 +0000 (15:34 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 11 Sep 2025 13:34:09 +0000 (15:34 +0200)
ircplom/client.py
ircplom/client_tui.py

index afb4502f2cd09777073ab78fad5392b78c780d5b..c958de781d11d12c25d6d7bfee2884ee4b8aa97c 100644 (file)
@@ -40,10 +40,17 @@ class AutoAttrMixin:
         return super().__getattribute__(key)
 
 
+class _Clearable(ABC):
+
+    @abstractmethod
+    def clear(self) -> None:
+        'Zero internal knowledge.'
+
+
 DictItem = TypeVar('DictItem')
 
 
-class Dict(Generic[DictItem]):
+class Dict(_Clearable, Generic[DictItem]):
     'Customized dict replacement.'
 
     def __init__(self, **kwargs) -> None:
@@ -58,7 +65,6 @@ class Dict(Generic[DictItem]):
         return self._dict[key]
 
     def clear(self) -> None:
-        'Zero content.'
         self._dict.clear()
 
     @property
@@ -105,7 +111,7 @@ class _Completable(ABC):
         'Set .completed to "complete" value if possible of current state.'
 
 
-class _CompletableStringsList(_Completable):
+class _CompletableStringsList(_Clearable, _Completable):
 
     def __init__(self) -> None:
         self._incomplete: list[str] = []
@@ -128,7 +134,6 @@ class _CompletableStringsList(_Completable):
         self.completed = tuple(self._incomplete)
 
     def clear(self) -> None:
-        'Wipe content and declare new emptiness as complete.'
         self._incomplete.clear()
         self.complete()
 
@@ -528,7 +533,7 @@ class _UpdatingChannelsDict(_UpdatingDict[_UpdatingChannel]):
                 channel.remove_user(user)
 
 
-class _ClientDb(_UpdatingMixin, SharedClientDbFields):
+class _ClientDb(_Clearable, _UpdatingMixin, SharedClientDbFields):
     _keep_on_clear = set(IrcConnSetup.__annotations__.keys())
     caps: _UpdatingDict[_UpdatingServerCapability]
     channels: _UpdatingChannelsDict
@@ -556,10 +561,9 @@ class _ClientDb(_UpdatingMixin, SharedClientDbFields):
         return attr
 
     def clear(self) -> None:
-        'Wipe updating attributes.'
         for key, value in [(k, v) for k, v in self._deep_annotations().items()
                            if k not in self._keep_on_clear]:
-            if hasattr(value, 'clear'):
+            if issubclass(value, _Clearable):
                 getattr(self, key).clear()
             elif issubclass(value, str):
                 setattr(self, key, '')
@@ -584,7 +588,7 @@ class _ClientDb(_UpdatingMixin, SharedClientDbFields):
         return toks[1]
 
 
-class _CapsManager:
+class _CapsManager(_Clearable):
 
     def __init__(self,
                  sender: Callable,
@@ -595,7 +599,6 @@ class _CapsManager:
         self.clear()
 
     def clear(self) -> None:
-        'Zero internal knowledge.'
         self._dict.clear()
         self._ls = _CompletableStringsList()
         self._list = _CompletableStringsList()
index 98ff459ec9067d659db83bed4bf89f85b2266970..b69ec963734420e8966d0644befee501c05292f6 100644 (file)
@@ -232,7 +232,7 @@ class _UpdatingUser(_UpdatingNode, NickUserHost):
             return super().set_and_check_for_change(update)
         if super().set_and_check_for_change(update):
             scope = self._scope(update.path)
-            msg = f'RAW: '
+            msg = 'RAW: '
             if update.path[-1] == 'nick':
                 return scope, msg + f'{self.prev} renames {update.value}'
             if update.path[-1] == 'exit_msg' and update.value: