From: Christian Heller Date: Thu, 25 Sep 2025 23:44:07 +0000 (+0200) Subject: Avoid mutables in class attribute defaults. X-Git-Url: https://plomlompom.com/repos/?a=commitdiff_plain;h=6e378fb2536f571ab62fd270a3f951ce56c47c59;p=ircplom Avoid mutables in class attribute defaults. --- 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]