diff libervia/backend/core/xmpp.py @ 4342:17fa953c8cd7

core (types): improve `SatXMPPEntity` core type and type hints.
author Goffi <goffi@goffi.org>
date Mon, 13 Jan 2025 01:23:10 +0100
parents e94799a0908f
children
line wrap: on
line diff
--- a/libervia/backend/core/xmpp.py	Wed Dec 11 01:17:09 2024 +0200
+++ b/libervia/backend/core/xmpp.py	Mon Jan 13 01:23:10 2025 +0100
@@ -518,7 +518,7 @@
             xs.add_hook(C.STREAM_HOOK_SEND, hook)
         super(SatXMPPEntity, self)._connected(xs)
 
-    def disconnect_profile(self, reason):
+    def disconnect_profile(self, reason: failure.Failure|None) -> None:
         if self._connected_d is not None:
             self.host_app.bridge.disconnected(
                 self.profile
@@ -581,7 +581,7 @@
             if disconnected_cb is not None:
                 yield disconnected_cb(self)
 
-    def is_connected(self):
+    def is_connected(self) -> bool:
         """Return True is client is fully connected
 
         client is considered fully connected if transport is started and all plugins
@@ -594,7 +594,7 @@
 
         return self._connected_d is not None and transport_connected
 
-    def entity_disconnect(self):
+    def entity_disconnect(self) -> defer.Deferred[None]:
         if not self.host_app.trigger.point("disconnecting", self):
             return
         log.info(_("Disconnecting..."))
@@ -606,7 +606,7 @@
 
     ## sending ##
 
-    def IQ(self, type_="set", timeout=60):
+    def IQ(self, type_="set", timeout=60) -> xmlstream.IQ:
         """shortcut to create an IQ element managing deferred
 
         @param type_(unicode): IQ type ('set' or 'get')
@@ -618,7 +618,13 @@
         iq_elt.timeout = timeout
         return iq_elt
 
-    def sendError(self, iq_elt, condition, text=None, appCondition=None):
+    def sendError(
+            self,
+            iq_elt: domish.Element,
+            condition: str,
+            text: str|None = None,
+            appCondition: str|None = None
+    ) -> None:
         """Send error stanza build from iq_elt
 
         @param iq_elt(domish.Element): initial IQ element
@@ -854,9 +860,9 @@
         """A message sending can be cancelled by a plugin treatment"""
         failure.trap(exceptions.CancelError)
 
-    def is_message_printable(self, mess_data):
+    def is_message_printable(self, mess_data: MessageData) -> bool:
         """Return True if a message contain payload to show in frontends"""
-        return (
+        return bool(
             mess_data["message"]
             or mess_data["subject"]
             or mess_data["extra"].get(C.KEY_ATTACHMENTS)