From a1dfdeac78bfef2c3cfb7170df37b90877471c9c Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Thu, 14 Aug 2025 14:53:05 +0200 Subject: [PATCH] Improve type safety of _ClientDb.conn_setup. --- ircplom/client.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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]: -- 2.30.2