From: Christian Heller Date: Fri, 26 Sep 2025 12:43:40 +0000 (+0200) Subject: Determine ClientDb.clear order so that more basic re-sets happen first. X-Git-Url: https://plomlompom.com/repos/?a=commitdiff_plain;h=b2027577f44af41e48b86e1258156cf1e376ce47;p=ircplom Determine ClientDb.clear order so that more basic re-sets happen first. --- diff --git a/src/ircplom/client.py b/src/ircplom/client.py index 63c6ed4..e4ffbb5 100644 --- a/src/ircplom/client.py +++ b/src/ircplom/client.py @@ -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): diff --git a/src/tests/test.txt b/src/tests/test.txt index 5af8ac6..7462aa0 100644 --- a/src/tests/test.txt +++ b/src/tests/test.txt @@ -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] @@ -320,22 +322,19 @@ 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 @@ -346,7 +345,6 @@ # 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)@+] @@ -354,6 +352,7 @@ 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] @@ -367,17 +366,16 @@ 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)@+] @@ -385,6 +383,7 @@ 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] @@ -399,12 +398,12 @@ 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