From: Christian Heller Date: Thu, 14 Aug 2025 12:53:05 +0000 (+0200) Subject: Improve type safety of _ClientDb.conn_setup. X-Git-Url: https://plomlompom.com/repos/booking/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/balance?a=commitdiff_plain;ds=sidebyside;p=ircplom Improve type safety of _ClientDb.conn_setup. --- diff --git a/ircplom/client.py b/ircplom/client.py index f914971..40f343e 100644 --- a/ircplom/client.py +++ b/ircplom/client.py @@ -229,10 +229,16 @@ class _ClientDb(ClientDbBase): @property def conn_setup(self) -> IrcConnSetup: 'Constructed out of stored entries *including* unconfirmed ones.' - kwargs: dict[str, Any] = {} + kwargs: dict[str, ClientDbType] = {} for field_name in IrcConnSetup._fields: - kwargs[field_name] = self._dict.get(field_name, None) - return IrcConnSetup(**kwargs) + val = self._dict.get(field_name, None) + if val is None: + raise CrashingException(f'field not set: {field_name}') + if not isinstance(val, IrcConnSetup.__annotations__[field_name]): + raise CrashingException( + f'wrong type for {field_name}: {type(val)} (value: {val})') + kwargs[field_name] = val + return IrcConnSetup(**kwargs) # type: ignore # enough tests above @property def caps(self) -> dict[str, _ServerCapability]: