From fed55d3dda2c01dca7e9b9ea036c4b7b756510ff Mon Sep 17 00:00:00 2001 From: mathieui Date: Wed, 21 Apr 2021 23:20:25 +0200 Subject: typing: matchers and senders Leftover error that I cannot fix: * https://github.com/python/mypy/issues/708 Leftover error that I am unsure of what to do: * xml handlers are not properly typed (it seems like nothing in slix is using it, considering a removal instead of adding an Union everywhere) --- slixmpp/xmlstream/handler/callback.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'slixmpp/xmlstream/handler/callback.py') diff --git a/slixmpp/xmlstream/handler/callback.py b/slixmpp/xmlstream/handler/callback.py index 93cec6b7..5d792bf9 100644 --- a/slixmpp/xmlstream/handler/callback.py +++ b/slixmpp/xmlstream/handler/callback.py @@ -1,10 +1,17 @@ - # slixmpp.xmlstream.handler.callback # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Part of Slixmpp: The Slick XMPP Library # :copyright: (c) 2011 Nathanael C. Fritz # :license: MIT, see LICENSE for more details +from __future__ import annotations + +from typing import Optional, Callable, Any, TYPE_CHECKING from slixmpp.xmlstream.handler.base import BaseHandler +from slixmpp.xmlstream.matcher.base import MatcherBase + +if TYPE_CHECKING: + from slixmpp.xmlstream.stanzabase import StanzaBase + from slixmpp.xmlstream.xmlstream import XMLStream class Callback(BaseHandler): @@ -28,8 +35,6 @@ class Callback(BaseHandler): :param matcher: A :class:`~slixmpp.xmlstream.matcher.base.MatcherBase` derived object for matching stanza objects. :param pointer: The function to execute during callback. - :param bool thread: **DEPRECATED.** Remains only for - backwards compatibility. :param bool once: Indicates if the handler should be used only once. Defaults to False. :param bool instream: Indicates if the callback should be executed @@ -38,31 +43,36 @@ class Callback(BaseHandler): :param stream: The :class:`~slixmpp.xmlstream.xmlstream.XMLStream` instance this handler should monitor. """ + _once: bool + _instream: bool + _pointer: Callable[[StanzaBase], Any] - def __init__(self, name, matcher, pointer, thread=False, - once=False, instream=False, stream=None): + def __init__(self, name: str, matcher: MatcherBase, + pointer: Callable[[StanzaBase], Any], + once: bool = False, instream: bool = False, + stream: Optional[XMLStream] = None): BaseHandler.__init__(self, name, matcher, stream) self._pointer = pointer self._once = once self._instream = instream - def prerun(self, payload): + def prerun(self, payload: StanzaBase) -> None: """Execute the callback during stream processing, if the callback was created with ``instream=True``. :param payload: The matched - :class:`~slixmpp.xmlstream.stanzabase.ElementBase` object. + :class:`~slixmpp.xmlstream.stanzabase.StanzaBase` object. """ if self._once: self._destroy = True if self._instream: self.run(payload, True) - def run(self, payload, instream=False): + def run(self, payload: StanzaBase, instream: bool = False) -> None: """Execute the callback function with the matched stanza payload. :param payload: The matched - :class:`~slixmpp.xmlstream.stanzabase.ElementBase` object. + :class:`~slixmpp.xmlstream.stanzabase.StanzaBase` object. :param bool instream: Force the handler to execute during stream processing. This should only be used by :meth:`prerun()`. Defaults to ``False``. -- cgit v1.2.3 From ed3bb878a75c84c2be74d1212226298967ee26e5 Mon Sep 17 00:00:00 2001 From: mathieui Date: Mon, 5 Jul 2021 22:28:38 +0200 Subject: handler: fix more types --- slixmpp/xmlstream/handler/callback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'slixmpp/xmlstream/handler/callback.py') diff --git a/slixmpp/xmlstream/handler/callback.py b/slixmpp/xmlstream/handler/callback.py index 5d792bf9..50dd4c66 100644 --- a/slixmpp/xmlstream/handler/callback.py +++ b/slixmpp/xmlstream/handler/callback.py @@ -45,13 +45,13 @@ class Callback(BaseHandler): """ _once: bool _instream: bool - _pointer: Callable[[StanzaBase], Any] def __init__(self, name: str, matcher: MatcherBase, pointer: Callable[[StanzaBase], Any], once: bool = False, instream: bool = False, stream: Optional[XMLStream] = None): BaseHandler.__init__(self, name, matcher, stream) + self._pointer: Callable[[StanzaBase], Any] = pointer self._pointer = pointer self._once = once self._instream = instream -- cgit v1.2.3