From af958fd1fe46d4a3f523ee3f4f103f15430b5fc2 Mon Sep 17 00:00:00 2001 From: mathieui Date: Mon, 5 Jul 2021 22:29:37 +0200 Subject: stanza: fix a bunch of type errors --- slixmpp/stanza/error.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'slixmpp/stanza/error.py') diff --git a/slixmpp/stanza/error.py b/slixmpp/stanza/error.py index 83742a5c..76c6b9cc 100644 --- a/slixmpp/stanza/error.py +++ b/slixmpp/stanza/error.py @@ -3,7 +3,7 @@ # This file is part of Slixmpp. # See the file LICENSE for copying permission. from __future__ import annotations -from typing import Optional +from typing import Optional, Dict, Type, ClassVar from slixmpp.xmlstream import ElementBase, ET @@ -50,10 +50,10 @@ class Error(ElementBase): name = 'error' plugin_attrib = 'error' interfaces = {'code', 'condition', 'text', 'type', - 'gone', 'redirect', 'by'} + 'gone', 'redirect', 'by'} sub_interfaces = {'text'} - plugin_attrib_map = {} - plugin_tag_map = {} + plugin_attrib_map: ClassVar[Dict[str, Type[ElementBase]]] = {} + plugin_tag_map: ClassVar[Dict[str, Type[ElementBase]]] = {} conditions = {'bad-request', 'conflict', 'feature-not-implemented', 'forbidden', 'gone', 'internal-server-error', 'item-not-found', 'jid-malformed', 'not-acceptable', @@ -66,7 +66,7 @@ class Error(ElementBase): condition_ns: str = 'urn:ietf:params:xml:ns:xmpp-stanzas' types = {'cancel', 'continue', 'modify', 'auth', 'wait'} - def setup(self, xml: Optional[ET.Element]=None): + def setup(self, xml: Optional[ET.Element] = None): """ Populate the stanza object using an optional XML object. @@ -83,7 +83,9 @@ class Error(ElementBase): self['type'] = 'cancel' self['condition'] = 'feature-not-implemented' if self.parent is not None: - self.parent()['type'] = 'error' + parent = self.parent() + if parent: + parent['type'] = 'error' def get_condition(self) -> str: """Return the condition element's name.""" @@ -106,7 +108,7 @@ class Error(ElementBase): self.xml.append(ET.Element("{%s}%s" % (self.condition_ns, value))) return self - def del_condition(self) -> None: + def del_condition(self) -> Error: """Remove the condition element.""" for child in self.xml: if "{%s}" % self.condition_ns in child.tag: -- cgit v1.2.3