Repository: biopython/biopython

Issue:
getiterator was removed in favor of iter in Python 3.9
https://github.com/biopython/biopython/blob/2b8559b7c1409cbc48d88a209f9db15c4731e53c/Bio/SeqIO/UniprotIO.py#L255

https://bugzilla.redhat.com/show_bug.cgi?id=1808737


Discussion:

Resolving patch:
diff --git a/Bio/KEGG/KGML/KGML_parser.py b/Bio/KEGG/KGML/KGML_parser.py
--- a/Bio/KEGG/KGML/KGML_parser.py
+++ b/Bio/KEGG/KGML/KGML_parser.py
@@ -115,7 +115,7 @@ def _parse_entry(element):
             new_entry = Entry()
             for k, v in element.attrib.items():
                 new_entry.__setattr__(k, v)
-            for subelement in element.getchildren():
+            for subelement in element:
                 if subelement.tag == "graphics":
                     _parse_graphics(subelement, new_entry)
                 elif subelement.tag == "component":
@@ -138,7 +138,7 @@ def _parse_reaction(element):
             new_reaction = Reaction()
             for k, v in element.attrib.items():
                 new_reaction.__setattr__(k, v)
-            for subelement in element.getchildren():
+            for subelement in element:
                 if subelement.tag == "substrate":
                     new_reaction.add_substrate(int(subelement.attrib["id"]))
                 elif subelement.tag == "product":
@@ -150,7 +150,7 @@ def _parse_relation(element):
             new_relation.entry1 = int(element.attrib["entry1"])
             new_relation.entry2 = int(element.attrib["entry2"])
             new_relation.type = element.attrib["type"]
-            for subtype in element.getchildren():
+            for subtype in element:
                 name, value = subtype.attrib["name"], subtype.attrib["value"]
                 if name in ("compound", "hidden compound"):
                     new_relation.subtypes.append((name, int(value)))
@@ -163,7 +163,7 @@ def _parse_relation(element):
         self.pathway = Pathway()
         # Get information about the pathway itself
         _parse_pathway(self.entry.attrib)
-        for element in self.entry.getchildren():
+        for element in self.entry:
             if element.tag == "entry":
                 _parse_entry(element)
             elif element.tag == "reaction":
diff --git a/Bio/Phylo/NeXMLIO.py b/Bio/Phylo/NeXMLIO.py
--- a/Bio/Phylo/NeXMLIO.py
+++ b/Bio/Phylo/NeXMLIO.py
@@ -138,10 +138,9 @@ def parse(self, values_are_confidence=False, rooted=False):
                 node_children = {}
                 root = None
 
-                child_tags = node.getchildren()
                 nodes = []
                 edges = []
-                for child in child_tags:
+                for child in node:
                     if child.tag == qUri("nex:node"):
                         nodes.append(child)
                     if child.tag == qUri("nex:edge"):
@@ -155,7 +154,7 @@ def parse(self, values_are_confidence=False, rooted=False):
                     if "root" in node.attrib and node.attrib["root"] == "true":
                         root = node_id
 
-                    for child in node.getchildren():
+                    for child in node:
                         if child.tag == qUri("nex:meta"):
                             self.add_annotation(node_dict[node_id], child)
 
@@ -176,7 +175,7 @@ def parse(self, values_are_confidence=False, rooted=False):
                     ):
                         node_dict[tar]["confidence"] = float(edge.attrib["content"])
 
-                    for child in edge.getchildren():
+                    for child in edge:
                         if child.tag == qUri("nex:meta"):
                             self.add_annotation(node_dict[tar], child)
 
diff --git a/Bio/SeqIO/UniprotIO.py b/Bio/SeqIO/UniprotIO.py
--- a/Bio/SeqIO/UniprotIO.py
+++ b/Bio/SeqIO/UniprotIO.py
@@ -252,11 +252,11 @@ def _parse_comment(element):
 
             if element.attrib["type"] in simple_comments:
                 ann_key = "comment_%s" % element.attrib["type"].replace(" ", "")
-                for text_element in element.getiterator(NS + "text"):
+                for text_element in element.iter(NS + "text"):
                     if text_element.text:
                         append_to_annotations(ann_key, text_element.text)
             elif element.attrib["type"] == "subcellular location":
-                for subloc_element in element.getiterator(NS + "subcellularLocation"):
+                for subloc_element in element.iter(NS + "subcellularLocation"):
                     for el in subloc_element:
                         if el.text:
                             ann_key = "comment_%s_%s" % (
@@ -265,34 +265,30 @@ def _parse_comment(element):
                             )
                             append_to_annotations(ann_key, el.text)
             elif element.attrib["type"] == "interaction":
-                for interact_element in element.getiterator(NS + "interactant"):
+                for interact_element in element.iter(NS + "interactant"):
                     ann_key = "comment_%s_intactId" % element.attrib["type"]
                     append_to_annotations(ann_key, interact_element.attrib["intactId"])
             elif element.attrib["type"] == "alternative products":
-                for alt_element in element.getiterator(NS + "isoform"):
+                for alt_element in element.iter(NS + "isoform"):
                     ann_key = "comment_%s_isoform" % element.attrib["type"].replace(
                         " ", ""
                     )
-                    for id_element in alt_element.getiterator(NS + "id"):
+                    for id_element in alt_element.iter(NS + "id"):
                         append_to_annotations(ann_key, id_element.text)
             elif element.attrib["type"] == "mass spectrometry":
                 ann_key = "comment_%s" % element.attrib["type"].replace(" ", "")
                 start = end = 0
-                for el in element.getiterator(NS + "location"):
-                    pos_els = list(el.getiterator(NS + "position"))
+                for el in element.iter(NS + "location"):
+                    pos_els = list(el.iter(NS + "position"))
                     # this try should be avoided, maybe it is safer to skip position parsing for mass spectrometry
                     try:
                         if pos_els:
                             end = int(pos_els[0].attrib["position"])
                             start = end - 1
                         else:
-                            start = int(
-                                list(el.getiterator(NS + "begin"))[0].attrib["position"]
-                            )
+                            start = int(next(el.iter(NS + "begin")).attrib["position"])
                             start -= 1
-                            end = int(
-                                list(el.getiterator(NS + "end"))[0].attrib["position"]
-                            )
+                            end = int(next(el.iter(NS + "end")).attrib["position"])
                     except (ValueError, KeyError):
                         # undefined positions or erroneously mapped
                         pass
@@ -307,9 +303,9 @@ def _parse_comment(element):
             elif element.attrib["type"] == "sequence caution":
                 pass  # not parsed: few information, complex structure
             elif element.attrib["type"] == "online information":
-                for link_element in element.getiterator(NS + "link"):
+                for link_element in element.iter(NS + "link"):
                     ann_key = "comment_%s" % element.attrib["type"].replace(" ", "")
-                    for id_element in link_element.getiterator(NS + "link"):
+                    for id_element in link_element.iter(NS + "link"):
                         append_to_annotations(
                             ann_key,
                             "%s@%s"


Test patch: