home · contact · privacy
Improve type safety of _ClientDb.conn_setup.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 14 Aug 2025 12:53:05 +0000 (14:53 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 14 Aug 2025 12:53:05 +0000 (14:53 +0200)
ircplom/client.py

index f914971ebcbe33cf011bc02d22576c10b2b5468d..40f343e4767e6e36b75a2af0ab26a02bc91b4e43 100644 (file)
@@ -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]: