You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As part of the upgrade to support Python 3.6+ only, many checks for sys.version_info are no longer required. Here is an approximate list:
$ grep "version_info" Bio/*.py Bio/*/*.py Bio/*/*/*.py Tests/*py
Bio/File.py:if (sys.version_info >= (3, 7)
Bio/File.py: or (sys.version_info == (3, 6)
Bio/File.py: if sys.version_info[0] >= 3 and "U" in mode:
Bio/Seq.py: if sys.version_info[0] == 3:
Bio/Seq.py: if sys.version_info[0] == 3:
Bio/SeqRecord.py: if sys.version_info[0] < 3:
Bio/bgzf.py: if sys.version_info[0] >= 3:
Bio/Phylo/BaseTree.py:if sys.version_info[0] < 3:
Bio/SearchIO/__init__.py:if sys.version_info < (3, 6):
Bio/SearchIO/__init__.py: if format == "blast-xml" and sys.version_info[0] > 2:
Bio/SeqIO/__init__.py:if sys.version_info < (3, 6):
Tests/common_BioSQL.py: if sys.version_info[0] == 2:
Tests/test_Phylo.py: if sys.version_info[0] < 3:
Tests/test_Phylo.py: if sys.version_info[0] < 3:
Tests/test_SeqIO_SeqXML.py: if not (sys.platform == "win32" and sys.version_info[0] >= 3):
Tests/test_SeqIO_index.py: if sys.version_info[0] < 3 or format in SeqIO._BinaryFormats:
Tests/test_SeqRecord.py: if sys.version_info[0] >= 3:
Tests/test_Seq_objs.py:if sys.version_info[0] < 3:
Tests/test_SffIO.py: if sys.platform != "win32" and sys.version_info[0] < 3:
Tests/test_geo.py:if sys.version_info[0] >= 3:
Tests/test_pairwise_aligner.py: if sys.version_info[0] >= 3:
I suggest tagging this with "Good first issue" and "Help wanted"
Note, the first case sys.version_info >= (3, 7) should be kept for now (although a separate discussion might be needed on whether or not it is safe to assume regular dicts retain insertion order from Python 3.6 onwards)
@chris-rands From the python mailing list, maintaining the insertion order of a dict is a language feature starting from 3.7. While it was a side-effect of a performance optimization in 3.6 (and wasn't recommended to be relied on), maintaining insertion order should be safe to assume in 3.7 and up.
Arguably we could say since the only Python implementations of Python 3.6 in the wild are CPython and PyPy (which both use ordered dictionaries) that we don't need to worry about this and can effectively already assume ordered dicts. My expectation is that any future Python 3 implementation (e.g. an updated Jython or IronPython?) will start with ordered dictionaries.
My inclination is to leave this bit of code as it is - sooner or later we'll drop Python 3.6 anyway.
--
Happily all the other cases @chris-rands flagged are a much simpler, Python 3 or at least 3.6 onwards (which is what we now are focussed on).
@peterjc@nimne Yes, with the caveat that equality comparisons are still ordered insensitive in Python 3.7 with regular dict, which leads to different behaviours:
That's an interesting subtle gotcha - although I don't think it would be an issue for the indexing code in Bio.File.
Anyway, Bio/File.py aside, we're making steady progress:
$ grep "version_info" */*.py Bio/*/*.py Bio/*/*/*.py
Bio/File.py: sys.version_info >= (3, 7)
Bio/File.py: or (sys.version_info == (3, 6) and platform.python_implementation() == "CPython")
Bio/File.py: if sys.version_info[0] >= 3 and "U" in mode:
Bio/bgzf.py: if sys.version_info[0] >= 3:
BioSQL/BioSeqDatabase.py: if module_name == "mysql.connector" and sys.version_info[0] == 3:
Tests/test_SeqIO_SeqXML.py: if not (sys.platform == "win32" and sys.version_info[0] >= 3):
Tests/test_SeqIO_index.py: if sys.version_info[0] < 3 or format in SeqIO._BinaryFormats:
Bio/Phylo/BaseTree.py:if sys.version_info[0] < 3:
Bio/SearchIO/__init__.py:if sys.version_info < (3, 6):
Bio/SearchIO/__init__.py: if format == "blast-xml" and sys.version_info[0] > 2:
Bio/SeqIO/__init__.py:if sys.version_info < (3, 6):
I realise now that we have ordered dictionary code in three places, Bio/File.py, Bio/SearchIO/__init__.py and Bio/SeqIO/__init__.py - and they were not consistent. Thus in #2518 I propose we remove the checks and assume ordered dictionaries.
$ grep "version_info" */*.py Bio/*/*.py Bio/*/*/*.py
Bio/File.py: if sys.version_info[0] >= 3 and "U" in mode:
BioSQL/BioSeqDatabase.py: if module_name == "mysql.connector" and sys.version_info[0] == 3:
Tests/test_SeqIO_SeqXML.py: if not (sys.platform == "win32" and sys.version_info[0] >= 3):
Bio/Phylo/BaseTree.py:if sys.version_info[0] < 3:
Bio/SearchIO/__init__.py: if format == "blast-xml" and sys.version_info[0] > 2:
There are four easy cases, just removing a clause from an if-statement. That would make a nice pull request (Bio/File.py, BioSQL/BioSeqDatabase.py, Tests/test_SeqIO_SeqXML.py and Bio/SearchIO/__init__.py)
For Bio/Phylo/BaseTree.py we need to remove the as_string function definition and replace all uses of it with str instead.
Bio/File.py: if sys.version_info[0] >= 3 and "U" in mode:
BioSQL/BioSeqDatabase.py: if module_name == "mysql.connector" and sys.version_info[0] == 3:
Tests/test_SeqIO_SeqXML.py: if not (sys.platform == "win32" and sys.version_info[0] >= 3):
Bio/SearchIO/__init__.py: if format == "blast-xml" and sys.version_info[0] > 2:
Activity
mdehoon commentedon Jan 4, 2020
Tests/test_pairwise_aligner.pyis being fixed in #2491 .I would suggest to make separate pull requests for each file.
lorforlinux commentedon Jan 6, 2020
Following files are being fixed (in #2496):
test_SeqIO_SeqXML.pyrequires special attention @peterjc @mdehoonsys.version_info use in test_SeqIO_index.py
nimne commentedon Jan 6, 2020
@chris-rands From the python mailing list, maintaining the insertion order of a
dictis a language feature starting from 3.7. While it was a side-effect of a performance optimization in 3.6 (and wasn't recommended to be relied on), maintaining insertion order should be safe to assume in 3.7 and up.peterjc commentedon Jan 6, 2020
@nimne yes, that's what the code in question does - it falls back on
OrderedDictunder Python 3.6 when not using CPython or PyPy:https://github.com/biopython/biopython/blob/biopython-176/Bio/File.py#L34
Arguably we could say since the only Python implementations of Python 3.6 in the wild are CPython and PyPy (which both use ordered dictionaries) that we don't need to worry about this and can effectively already assume ordered dicts. My expectation is that any future Python 3 implementation (e.g. an updated Jython or IronPython?) will start with ordered dictionaries.
My inclination is to leave this bit of code as it is - sooner or later we'll drop Python 3.6 anyway.
--
Happily all the other cases @chris-rands flagged are a much simpler, Python 3 or at least 3.6 onwards (which is what we now are focussed on).
chris-rands commentedon Jan 6, 2020
@peterjc @nimne Yes, with the caveat that equality comparisons are still ordered insensitive in Python 3.7 with regular
dict, which leads to different behaviours:Remove python2 checks from Test/ (#2496)
peterjc commentedon Jan 7, 2020
That's an interesting subtle gotcha - although I don't think it would be an issue for the indexing code in
Bio.File.Anyway,
Bio/File.pyaside, we're making steady progress:Note #2499 will do
Tests/test_SeqIO_SeqXML.pysys.version_info use in test_SeqIO_index.py
peterjc commentedon Jan 9, 2020
I realise now that we have ordered dictionary code in three places,
Bio/File.py,Bio/SearchIO/__init__.pyandBio/SeqIO/__init__.py- and they were not consistent. Thus in #2518 I propose we remove the checks and assume ordered dictionaries.peterjc commentedon Jan 9, 2020
Updated list assuming #2517 and #2518 are merged:
There are four easy cases, just removing a clause from an if-statement. That would make a nice pull request (
Bio/File.py,BioSQL/BioSeqDatabase.py,Tests/test_SeqIO_SeqXML.pyandBio/SearchIO/__init__.py)For
Bio/Phylo/BaseTree.pywe need to remove theas_stringfunction definition and replace all uses of it withstrinstead.lorforlinux commentedon Jan 9, 2020
Fixed these in #2520
mdehoon commentedon Jan 10, 2020
Bio.Phylo.BaseTreein #2526peterjc commentedon Jan 10, 2020
I've cherry-picked b07676d from #2517, so once #2526 is merged we can close this issue.
peterjc commentedon Jan 10, 2020
Closing - thank you everyone!