Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits: 5a804eaf by lovetox at 2022-01-24T23:33:06+01:00 Errors: Add type annotations - - - - - b3010f91 by lovetox at 2022-01-24T23:33:30+01:00 Add type annotations - - - - - 3 changed files: - nbxmpp/errors.py - nbxmpp/protocol.py - nbxmpp/task.py Changes: ===================================== nbxmpp/errors.py ===================================== @@ -15,9 +15,13 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. +from __future__ import annotations + import logging +from typing import Optional from nbxmpp.namespaces import Namespace +from nbxmpp.protocol import Protocol def is_error(error): @@ -25,14 +29,14 @@ def is_error(error): class BaseError(Exception): - def __init__(self, is_fatal=False): + def __init__(self, is_fatal: bool = False) -> None: self.is_fatal = is_fatal self.text = '' - def __str__(self): + def __str__(self) -> str: return self.text - def get_text(self, pref_lang=None): + def get_text(self, pref_lang: Optional[str] = None) -> str: return self.text @@ -41,18 +45,18 @@ class StanzaError(BaseError): log_level = logging.INFO app_namespace = None - def __init__(self, stanza): + def __init__(self, stanza: Protocol): BaseError.__init__(self) self.stanza = stanza self._stanza_name = stanza.getName() self._error_node = stanza.getTag('error') - self.condition = stanza.getError() + self.condition: Optional[str] = stanza.getError() self.condition_data = self._error_node.getTagData(self.condition) self.app_condition = self._get_app_condition() self.type = stanza.getErrorType() self.jid = stanza.getFrom() self.id = stanza.getID() - self._text = {} + self._text: dict[str, str] = {} text_elements = self._error_node.getTags('text', namespace=Namespace.STANZAS) @@ -61,7 +65,7 @@ class StanzaError(BaseError): text = element.getData() self._text[lang] = text - def _get_app_condition(self): + def _get_app_condition(self) -> Optional[str]: if self.app_namespace is None: return None @@ -70,7 +74,7 @@ class StanzaError(BaseError): return node.getName() return None - def get_text(self, pref_lang=None): + def get_text(self, pref_lang: Optional[str] = None) -> str: if pref_lang is not None: text = self._text.get(pref_lang) if text is not None: @@ -87,10 +91,10 @@ class StanzaError(BaseError): return self._text.popitem()[1] return '' - def set_text(self, lang, text): + def set_text(self, lang: str, text: str) -> None: self._text[lang] = text - def __str__(self): + def __str__(self) -> str: condition = self.condition if self.app_condition is not None: condition = '%s (%s)' % (self.condition, self.app_condition) ===================================== nbxmpp/protocol.py ===================================== @@ -936,7 +936,7 @@ class Protocol(Node): """ self.setAttr('id', val) - def getError(self): + def getError(self) -> Optional[str]: """ Return the error-condition (if present) or the textual description of the error (otherwise) ===================================== nbxmpp/task.py ===================================== @@ -267,7 +267,7 @@ class Task: return self._error return self._result - def finish(self): + def finish(self) -> Any: if self._error is not None: raise self._error # pylint: disable=raising-bad-type return self._result View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/-/compare/f79f9df663b7661b602e462fe45cfd7d60b0b0d3...b3010f9118066b4d5b88d49fbb327ebad94726f1 -- View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/-/compare/f79f9df663b7661b602e462fe45cfd7d60b0b0d3...b3010f9118066b4d5b88d49fbb327ebad94726f1 You're receiving this email because of your account on dev.gajim.org.
_______________________________________________ Commits mailing list [email protected] https://lists.gajim.org/cgi-bin/listinfo/commits
