Skip to content

Use iter instead of getiterator for Python 3.9 compatibility. - #2774

Merged
peterjc merged 4 commits into
biopython:masterfrom
tirkarthi:fix-getiterator
May 10, 2020
Merged

peterjc merged 4 commits into
biopython:masterfrom
tirkarthi:fix-getiterator

Conversation

@tirkarthi

@tirkarthi tirkarthi commented Mar 1, 2020 •

Copy link
Copy Markdown
Contributor

This pull request addresses issue #2773

  • I hereby agree to dual licence this and any previous contributions under both
    the Biopython License Agreement AND the BSD 3-Clause License.

  • I have read the CONTRIBUTING.rst file, have run flake8 locally, and
    understand that AppVeyor and TravisCI will be used to confirm the Biopython unit
    tests and style checks pass with these changes.

  • I have added my name to the alphabetical contributors listings in the files
    NEWS.rst and CONTRIB.rst as part of this pull request, am listed
    already, or do not wish to be listed. (This acknowledgement is optional.)

Fixes #2773

@tirkarthi
tirkarthi requested a review from peterjc as a code owner March 1, 2020 05:04
@codecov

codecov Bot commented Mar 1, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #2774 into master will increase coverage by 0.14%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2774      +/-   ##
==========================================
+ Coverage   83.97%   84.12%   +0.14%     
==========================================
  Files         319      319              
  Lines       50341    50354      +13     
==========================================
+ Hits        42276    42360      +84     
+ Misses       8065     7994      -71     
Impacted Files Coverage Δ
Bio/KEGG/KGML/KGML_parser.py 80.00% <100.00%> (ø)
Bio/Phylo/NeXMLIO.py 89.57% <100.00%> (-0.25%) ⬇️
Bio/SeqIO/UniprotIO.py 95.06% <100.00%> (ø)
Bio/Phylo/NewickIO.py 82.38% <0.00%> (-0.40%) ⬇️
Bio/SeqIO/InsdcIO.py 92.80% <0.00%> (+0.01%) ⬆️
Bio/SeqIO/AbiIO.py 95.65% <0.00%> (+0.02%) ⬆️
Bio/SeqIO/PdbIO.py 94.89% <0.00%> (+0.03%) ⬆️
Bio/Phylo/BaseTree.py 89.15% <0.00%> (+0.11%) ⬆️
Bio/SeqIO/PirIO.py 88.23% <0.00%> (+0.14%) ⬆️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c186054...ecadd3f. Read the comment docs.

@mdehoon

mdehoon commented Mar 1, 2020

Copy link
Copy Markdown
Contributor

@tirkarthi Isn't iter supposed to be a function?

@tirkarthi

Copy link
Copy Markdown
Contributor Author

@mdehoon

mdehoon commented Mar 1, 2020

Copy link
Copy Markdown
Contributor

@tirkarthi OK then, thanks.

@sagitter

sagitter commented Mar 1, 2020

Copy link
Copy Markdown
Contributor

test_KGML_graphics.py fails after applying #fc2b339 with Python-3.9.0a4:

Skipping any tests requiring internet access
Python version: 3.9.0a4 (default, Feb 27 2020, 00:00:00) 
[GCC 10.0.1 20200216 (Red Hat 10.0.1-0.8)]
Operating system: posix linux
+ for test in `ls test_*.py | grep -v Nexus | grep -v Phylo | grep -v Tutorial | grep -v bgzf | grep -v SearchIO_blast | grep -v pairwise_aligner | grep -v SubsMat`
+ echo C
+ export PYTHONPATH=/builddir/build/BUILDROOT/python-biopython-1.76-3.fc33.x86_64/usr/lib64/python3.9/site-packages
+ PYTHONPATH=/builddir/build/BUILDROOT/python-biopython-1.76-3.fc33.x86_64/usr/lib64/python3.9/site-packages
C
+ /usr/bin/python3 run_tests.py --offline -v test_KGML_graphics.py
test_KGML_graphics ... FAIL
test_render_KGML_basic (test_KGML_graphics.KGMLPathwayTest)
Basic rendering of KGML: write to PDF without modification. ... ERROR
test_render_KGML_modify (test_KGML_graphics.KGMLPathwayTest)
Rendering of KGML to PDF, with modification. ... ERROR
test_render_KGML_transparency (test_KGML_graphics.KGMLPathwayTest)
Rendering of KGML to PDF, with color alpha channel. ... ERROR

======================================================================
ERROR: test_render_KGML_basic (test_KGML_graphics.KGMLPathwayTest)
Basic rendering of KGML: write to PDF without modification.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/python-biopython-1.76/python3/Tests/test_KGML_graphics.py", line 112, in test_render_KGML_basic
    with open(p.infilename, "rU") as f:
ValueError: invalid mode: 'rU'

======================================================================
ERROR: test_render_KGML_modify (test_KGML_graphics.KGMLPathwayTest)
Rendering of KGML to PDF, with modification.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/python-biopython-1.76/python3/Tests/test_KGML_graphics.py", line 125, in test_render_KGML_modify
    pathway = read(f)
  File "/builddir/build/BUILD/python-biopython-1.76/python3/build/lib.linux-x86_64-3.9/Bio/KEGG/KGML/KGML_parser.py", line 43, in read
    first = next(iterator)
  File "/builddir/build/BUILD/python-biopython-1.76/python3/build/lib.linux-x86_64-3.9/Bio/KEGG/KGML/KGML_parser.py", line 77, in parse
    yield KGMLParser(elem).parse()
  File "/builddir/build/BUILD/python-biopython-1.76/python3/build/lib.linux-x86_64-3.9/Bio/KEGG/KGML/KGML_parser.py", line 172, in parse
    for element in self.entry.getchildren():
AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getchildren'

======================================================================
ERROR: test_render_KGML_transparency (test_KGML_graphics.KGMLPathwayTest)
Rendering of KGML to PDF, with color alpha channel.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/python-biopython-1.76/python3/Tests/test_KGML_graphics.py", line 156, in test_render_KGML_transparency
    pathway = read(f)
  File "/builddir/build/BUILD/python-biopython-1.76/python3/build/lib.linux-x86_64-3.9/Bio/KEGG/KGML/KGML_parser.py", line 43, in read
    first = next(iterator)
  File "/builddir/build/BUILD/python-biopython-1.76/python3/build/lib.linux-x86_64-3.9/Bio/KEGG/KGML/KGML_parser.py", line 77, in parse
    yield KGMLParser(elem).parse()
  File "/builddir/build/BUILD/python-biopython-1.76/python3/build/lib.linux-x86_64-3.9/Bio/KEGG/KGML/KGML_parser.py", line 172, in parse
    for element in self.entry.getchildren():
AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getchildren'

----------------------------------------------------------------------
Ran 1 test in 0.372 seconds

FAILED (failures = 1)

@tirkarthi

Copy link
Copy Markdown
Contributor Author

These are different errors.

  1. U mode in open was removed.
  2. list() should be instead of getchildren or just iteration needs to be done. This is also done in the Cpython bug linked. I will push these changes too with the PR.

@tirkarthi

Copy link
Copy Markdown
Contributor Author

U flag error has been fixed with ba893ee

@tirkarthi
tirkarthi requested a review from etal as a code owner March 1, 2020 13:06
@tirkarthi

Copy link
Copy Markdown
Contributor Author

I have pushed 9c2879e for getchildren related issues. Please test the same.

@sagitter

sagitter commented Mar 1, 2020

Copy link
Copy Markdown
Contributor

I have pushed 9c2879e for getchildren related issues. Please test the same.

Successfully tested with Python-3.9.0a4

@tirkarthi

Copy link
Copy Markdown
Contributor Author

Thanks :)

Comment thread NEWS.rst Resolved

@peterjc peterjc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. This looks good, will leave this a couple of days in case anyone else want to review, then I think a squash-and-merge would be appropriate.

@tirkarthi

Copy link
Copy Markdown
Contributor Author

Thanks for the quick review :)

Comment thread Bio/Phylo/NeXMLIO.py Outdated
child_tags = list(node)
nodes = []
edges = []
for child in child_tags:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

child_tags is no longer used. Why not iterate just node?

Suggested change
for child in child_tags:
for child in node:

Comment thread Bio/SeqIO/UniprotIO.py Outdated
end = int(
list(el.getiterator(NS + "end"))[0].attrib["position"]
)
end = int(list(el.iter(NS + "end"))[0].attrib["position"])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
end = int(list(el.iter(NS + "end"))[0].attrib["position"])
end = int(next(el.iter(NS + "end")).attrib["position"])

@peterjc

peterjc commented Mar 13, 2020

Copy link
Copy Markdown
Member

@serhiy-storchaka do you also agree to dual license your contributions?

@peterjc

peterjc commented May 6, 2020

Copy link
Copy Markdown
Member

If we don't have the license permission from @serhiy-storchaka we'll have to revert that commit and merge without it.

@serhiy-storchaka

Copy link
Copy Markdown
Contributor

@serhiy-storchaka do you also agree to dual license your contributions?

Yes, of course. I agree to dual license my contributions. Although they are trivial.

@peterjc

peterjc commented May 10, 2020

Copy link
Copy Markdown
Member

Excellent, thank you all. Merging...

@peterjc
peterjc merged commit 91f1db5 into biopython:master May 10, 2020
peterjc added a commit to peterjc/biopython that referenced this pull request Nov 15, 2020
Original author Ben Morris, and Frank Kauff,
Cymon Cox and Eric Talvich on whose work it was
partly based, and the other contributors since
as recorded by version control have agrred:

 - Andrew Dalke (@adalke)
   http://mailman.open-bio.org/pipermail/biopython-dev/2013-August/019941.html
 - Bartek Wilczyński (@barwil)
   http://mailman.open-bio.org/pipermail/biopython/2018-August/016533.html
 - Ben Morris (@bendmorris)
   biopython#898 (comment)
 - Carlos Pena (@carlosp420)
   biopython#898 (comment)
 - Chris Rands (@chris-rands)
   biopython#1301
 - Christian Brueffer (@cbrueffer)
   biopython#898 (comment)
 - Cymon Cox (@cymon)
   biopython#898 (comment)
 - Eric Talevich (@etal)
   biopython#898 (comment)
 - Frank Kauff (CVS username fkauff, on GitHub as @frankkl)
   biopython#2246 (comment)
 - Karthikeyan Singaravelan (@tirkarthi)
   biopython#2774
 - Michiel de Hoon (@mdehoon)
   biopython#898 (comment)
 - @morrme
   biopython#1172 (comment)
 - Peter Cock (@peterjc)
   biopython#898 (comment)
 - Sergio Valqui (@svalqui)
   biopython#1749
 - Sourav Singh (@souravsingh)
   biopython#957
 - Suresh Panneerselvam (@Amrithasuresh)
   biopython#1575
 - Thomas Hamelryck (CVS username nisse)
   https://mailman.open-bio.org/pipermail/biopython/2018-September/016546.html
peterjc added a commit that referenced this pull request Dec 3, 2020
JoaoRodrigues pushed a commit to JoaoRodrigues/biopython that referenced this pull request Jun 3, 2021
Original author Ben Morris, and Frank Kauff,
Cymon Cox and Eric Talvich on whose work it was
partly based, and the other contributors since
as recorded by version control have agrred:

 - Andrew Dalke (@adalke)
   http://mailman.open-bio.org/pipermail/biopython-dev/2013-August/019941.html
 - Bartek Wilczyński (@barwil)
   http://mailman.open-bio.org/pipermail/biopython/2018-August/016533.html
 - Ben Morris (@bendmorris)
   biopython#898 (comment)
 - Carlos Pena (@carlosp420)
   biopython#898 (comment)
 - Chris Rands (@chris-rands)
   biopython#1301
 - Christian Brueffer (@cbrueffer)
   biopython#898 (comment)
 - Cymon Cox (@cymon)
   biopython#898 (comment)
 - Eric Talevich (@etal)
   biopython#898 (comment)
 - Frank Kauff (CVS username fkauff, on GitHub as @frankkl)
   biopython#2246 (comment)
 - Karthikeyan Singaravelan (@tirkarthi)
   biopython#2774
 - Michiel de Hoon (@mdehoon)
   biopython#898 (comment)
 - @morrme
   biopython#1172 (comment)
 - Peter Cock (@peterjc)
   biopython#898 (comment)
 - Sergio Valqui (@svalqui)
   biopython#1749
 - Sourav Singh (@souravsingh)
   biopython#957
 - Suresh Panneerselvam (@Amrithasuresh)
   biopython#1575
 - Thomas Hamelryck (CVS username nisse)
   https://mailman.open-bio.org/pipermail/biopython/2018-September/016546.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getiterator was removed in favor of iter in Python 3.9

5 participants