home · contact · privacy
Determine ClientDb.clear order so that more basic re-sets happen first.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 26 Sep 2025 12:43:40 +0000 (14:43 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 26 Sep 2025 12:43:40 +0000 (14:43 +0200)
src/ircplom/client.py
src/tests/test.txt

index 63c6ed4bc7d6f29382592d2970110655fbcca847..e4ffbb5748c735244d10ac9a5772a74fa01995f2 100644 (file)
@@ -719,8 +719,13 @@ class _ClientDb(_Clearable, _UpdatingAttrsMixin, SharedClientDbFields):
         return updates
 
     def clear(self) -> None:
-        for key, value in [(k, v) for k, v in self._deep_annotations().items()
-                           if k not in self._keep_on_clear]:
+        # re-set isupports first, since other items depend on its defaults,
+        # e.g. .users.userlen
+        start_with = ['isupport']
+        for key in start_with + sorted(
+                k for k in self._deep_annotations().keys()
+                if k not in self._keep_on_clear | set(start_with)):
+            value = self._deep_annotations()[key]
             if hasattr(value, '__origin__'):
                 value = value.__origin__
             if issubclass(value, _Clearable):
index 5af8ac6d88f15cf5ac3b585f80237a47faa0aaea..7462aa0a4e10924ae7ada2774c4faca88ccd3332 100644 (file)
@@ -2,14 +2,16 @@
 
 # on /connect init databases, log in new windows
 > /connect foo.bar.baz foo:bar baz:foobarbazquux
-, $ DISCONNECTED
+|isupport-clear-in
 1 $ isupport cleared
 1 $ isupport:CHANTYPES set to: [#&]
 1 $ isupport:PREFIX set to: [(ov)@+]
 1 $ isupport:USERLEN set to: [10]
+|isupport-clear-out
 1 $ caps cleared
 1 $ users cleared
 1 $ channels cleared
+, $ DISCONNECTED
 
 # connect with values set by /connect, init CAP negotation
 1 $ hostname set to: [foo.bar.baz]
 1 $ channels:#testtest:exits:me cleared
 0:1 < ERROR :Closing link: (~foobarbaz@baz.bar.foo) [Quit: ircplom says bye]
 1 $ connection_state set to: [Closing link: (~foobarbaz@baz.bar.foo) [Quit: ircplom says bye]]
+repeat isupport-clear-in isupport-clear-out
+1 $ caps cleared
+1 $ channels cleared
 1 $ connection_state set to: []
 2,3,4,5,6,7 $ DISCONNECTED
-1 $ isupport cleared
-1 $ isupport:CHANTYPES set to: [#&]
-1 $ isupport:PREFIX set to: [(ov)@+]
-1 $ isupport:USERLEN set to: [10]
 1 $ motd set to:
 1 $ sasl_account set to: []
 1 $ sasl_auth_state set to: []
-1 $ caps cleared
-1 $ channels cleared
-1 $ users cleared
 
 # fail to send in disconnect, check alert window is command prompt window
 > /window 6
 > /privmsg barbar test
+1 $ users cleared
 6 !$ cannot send, connection seems closed
 > /window 1
 > /privmsg barbar test
 
 # test setting up second client, but 432 irrecoverably
 > /connect baz.bar.foo ?foo foo:foo
-, $ DISCONNECTED
 8 $ isupport cleared
 8 $ isupport:CHANTYPES set to: [#&]
 8 $ isupport:PREFIX set to: [(ov)@+]
 8 $ caps cleared
 8 $ users cleared
 8 $ channels cleared
+, $ DISCONNECTED
 8 $ hostname set to: [baz.bar.foo]
 8 $ port set to: [-1]
 8 $ nick_wanted set to: [?foo]
 1:8 > USER foo 0 * :foo
 1:8 > NICK :?foo
 1:8 < :*.?.net 432 * ?foo :Erroneous nickname
-8 $ connection_state set to: []
-, $ DISCONNECTED
 8 $ isupport cleared
 8 $ isupport:CHANTYPES set to: [#&]
 8 $ isupport:PREFIX set to: [(ov)@+]
 8 $ isupport:USERLEN set to: [10]
+8 $ connection_state set to: []
+, $ DISCONNECTED
 8 !$ nickname refused for bad format, giving up
 
 # test failing third connection
 > /connect baz.baz.baz baz baz:baz
-, $ DISCONNECTED
 9 $ isupport cleared
 9 $ isupport:CHANTYPES set to: [#&]
 9 $ isupport:PREFIX set to: [(ov)@+]
 9 $ caps cleared
 9 $ users cleared
 9 $ channels cleared
+, $ DISCONNECTED
 9 $ hostname set to: [baz.baz.baz]
 9 $ port set to: [-1]
 9 $ nick_wanted set to: [baz]
 2:9 > NICK :baz
 2: < FAKE_IRC_CONN_ABORT_EXCEPTION
 9 $ connection_state set to: [broken: FAKE_IRC_CONN_ABORT_EXCEPTION]
-9 $ connection_state set to: []
-, $ DISCONNECTED
 9 $ isupport cleared
 9 $ isupport:CHANTYPES set to: [#&]
 9 $ isupport:PREFIX set to: [(ov)@+]
 9 $ isupport:USERLEN set to: [10]
+9 $ connection_state set to: []
+, $ DISCONNECTED
 
 # check that (save TUI tests assuming start on window 0, and no 4 yet) on reconnect, all the same effects can be expected
 > /reconnect