diff --git a/odf/element.py b/odf/element.py index b2608ad..56055a3 100644 --- a/odf/element.py +++ b/odf/element.py @@ -365,7 +365,7 @@ def __init__(self, attributes=None, text=None, cdata=None, qname=None, qattribut allowed_attrs = self.allowed_attributes() if allowed_attrs is not None: allowed_args = [ a[1].lower().replace('-','') for a in allowed_attrs] - self.attributes={} + self.attributes={} # type: dict[tuple[str, str], ...] # Load the attributes from the 'attributes' argument if attributes: for attr, value in attributes.items(): @@ -391,6 +391,7 @@ def __init__(self, attributes=None, text=None, cdata=None, qname=None, qattribut raise AttributeError( "Required attribute missing: %s in <%s>" % (r[1].lower().replace('-',''), self.tagName)) def get_knownns(self, prefix): + # type: (Element, str) -> str | None """ Odfpy maintains a list of known namespaces. In some cases a prefix is used, and we need to know which namespace it resolves to. """ @@ -410,6 +411,7 @@ def get_nsprefix(self, namespace): return prefix def allowed_attributes(self): + # type: (Element) -> tuple[tuple[str, str], ...] return grammar.allowed_attributes.get(self.qname) def _setOwnerDoc(self, element): @@ -418,6 +420,7 @@ def _setOwnerDoc(self, element): self._setOwnerDoc(child) def addElement(self, element, check_grammar=True): + # type: (Element, Element, bool) -> None """ adds an element to an Element Element.addElement(Element) @@ -450,6 +453,7 @@ def addCDATA(self, cdata, check_grammar=True): self.appendChild(CDATASection(cdata)) def removeAttribute(self, attr, check_grammar=True): + # type: (Element, str | tuple[str, str], bool) -> None """ Removes an attribute by name. """ allowed_attrs = self.allowed_attributes() if allowed_attrs is None: @@ -467,6 +471,7 @@ def removeAttribute(self, attr, check_grammar=True): self.removeAttrNS(allowed_attrs[i][0], allowed_attrs[i][1]) def setAttribute(self, attr, value, check_grammar=True): + # type: (Element, str | tuple[str, str], Any, bool) -> None """ Add an attribute to the element This is sort of a convenience method. All attributes in ODF have namespaces. The library knows what attributes are legal and then allows @@ -493,6 +498,7 @@ def setAttribute(self, attr, value, check_grammar=True): self.setAttrNS(allowed_attrs[i][0], allowed_attrs[i][1], value) def setAttrNS(self, namespace, localpart, value): + # type: (Element, str, str, Any) -> None """ Add an attribute to the element In case you need to add an attribute the library doesn't know about then you must provide the full qualified name @@ -507,6 +513,7 @@ def setAttrNS(self, namespace, localpart, value): self.attributes[(namespace, localpart)] = c.convert((namespace, localpart), value, self) def getAttrNS(self, namespace, localpart): + # type: (Element, str, str) -> Any """ gets an attribute, given a namespace and a key @param namespace a unicode string or a bytes: the namespace @@ -529,9 +536,11 @@ def getAttrNS(self, namespace, localpart): return result def removeAttrNS(self, namespace, localpart): + # type: (Element, str, str) -> None del self.attributes[(namespace, localpart)] def getAttribute(self, attr): + # type: (str | tuple[str, str]) -> Any """ Get an attribute value. The method knows which namespace the attribute is in """ allowed_attrs = self.allowed_attributes() @@ -582,6 +591,7 @@ def toXml(self, level, f): f.write(u'/>') def _getElementsByObj(self, obj, accumulator): + # type: (Element, Element, list[Element]) -> list[Element] if self.qname == obj.qname: accumulator.append(self) for e in self.childNodes: @@ -590,11 +600,13 @@ def _getElementsByObj(self, obj, accumulator): return accumulator def getElementsByType(self, element): + # type: (Element, ...) -> list[Element] """ Gets elements based on the type, which is function from text.py, draw.py etc. """ obj = element(check_grammar=False) return self._getElementsByObj(obj,[]) def isInstanceOf(self, element): + # type: (Element, ...) -> bool """ This is a check to see if the object is an instance of a type """ obj = element(check_grammar=False) return self.qname == obj.qname diff --git a/odf/opendocument.py b/odf/opendocument.py index 25d736b..f3b10de 100644 --- a/odf/opendocument.py +++ b/odf/opendocument.py @@ -754,6 +754,7 @@ def getMediaType(self): return self.mimetype def getStyleByName(self, name): + # type: (str) -> element.Element """ Finds a style object based on the name @param name unicode string the name of style to search @@ -770,6 +771,7 @@ def getStyleByName(self, name): return result def getElementsByType(self, elt): + # type: (...) -> list[element.Element] """ Gets elements based on the type, which is function from text.py, draw.py etc.