From 6e378fb2536f571ab62fd270a3f951ce56c47c59 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Fri, 26 Sep 2025 01:44:07 +0200 Subject: [PATCH] Avoid mutables in class attribute defaults. --- src/ircplom/client.py | 8 ++++++-- src/test.txt | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ircplom/client.py b/src/ircplom/client.py index b2eca33..1473807 100644 --- a/src/ircplom/client.py +++ b/src/ircplom/client.py @@ -636,14 +636,18 @@ class _UpdatingIsupportDict(_UpdatingDict[str]): class _ClientDb(_Clearable, _UpdatingAttrsMixin, SharedClientDbFields): - _updates_cache: dict[tuple[str, ...], Any] = {} - _keep_on_clear = set(IrcConnSetup.__annotations__.keys()) + _updates_cache: dict[tuple[str, ...], Any] + _keep_on_clear = frozenset(IrcConnSetup.__annotations__.keys()) caps: _UpdatingDict[_UpdatingServerCapability] channels: _UpdatingChannelsDict isupport: _UpdatingIsupportDict motd: _UpdatingCompletableStringsOrdered users: _UpdatingUsersDict + def __init__(self, **kwargs) -> None: + self._updates_cache = {} + super().__init__(**kwargs) + def __getattribute__(self, key: str): attr = super().__getattribute__(key) if key == 'channels' and attr._create_if_none is None\ diff --git a/src/test.txt b/src/test.txt index 7c1c154..c691572 100644 --- a/src/test.txt +++ b/src/test.txt @@ -381,10 +381,14 @@ # 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 $ isupport:USERLEN set to: [10] +8 $ caps cleared +8 $ users cleared +8 $ channels cleared 8 $ hostname set to: [baz.bar.foo] 8 $ port set to: [-1] 8 $ nick_wanted set to: [?foo] @@ -408,10 +412,14 @@ # 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 $ isupport:USERLEN set to: [10] +9 $ caps cleared +9 $ users cleared +9 $ channels cleared 9 $ hostname set to: [baz.baz.baz] 9 $ port set to: [-1] 9 $ nick_wanted set to: [baz] -- 2.30.2