Repository navigation
String and bytes functions removal - #2445
Andrey-Raspopov wants to merge 21 commits into
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2445 +/- ##
==========================================
- Coverage 84.66% 84.65% -0.01%
==========================================
Files 323 323
Lines 52573 52622 +49
==========================================
+ Hits 44510 44549 +39
- Misses 8063 8073 +10
Continue to review full report at Codecov.
|
|
I'm not sure about introducing Currently as I recall |
|
Okay, I'll move it back to _utils then. |
|
It looks like Python 3.6 on TravisCI was failing due to this - perhaps the version of wheel is important: |
| from Bio._utils import as_bytes | ||
|
|
||
| handle = BytesIO(_as_bytes(handle.read())) | ||
| handle = BytesIO(as_bytes(handle.read())) |
There was a problem hiding this comment.
I am not sure why we need this; users should pass a BytesIO object, not a StringIO object to the read function. I can't think of a scenario in which the user /has/ to pass a StringIO object.
There was a problem hiding this comment.
A common use case would be user saved an XML file to disk, and just did open(xml_filename) which would be a unicode handle now.
There was a problem hiding this comment.
Then Entrez.read should raise an Exception. We should not be second-guessing the user.
There was a problem hiding this comment.
If it fails with a clear message, that's fine by me. I would lean to doing this in a follow up pull request so as not to delay this one editing many files.
There was a problem hiding this comment.
See this test in test_Entrez_parser.py:
def test_text_handle(self):
"""Test parsing a handle opened in text mode."""
with open("Entrez/einfo1.xml", "rt") as handle:
record = Entrez.read(handle)
self.assertIn("DbList", record)
or this one:
def test_StringIO(self):
"""Test parsing a StringIO handle (unicode not bytes)."""
with open("Entrez/einfo1.xml", "rt") as in_handle:
data = in_handle.read()
handle = StringIO(data)
record = Entrez.read(handle)
self.assertIn("DbList", record)
handle.close()
and the documentation has this example:
>>> from Bio import Entrez
>>> Entrez.email = "[email protected]" # Always tell NCBI who you are
>>> handle = open("Homo_sapiens.xml")
>>> records = Entrez.parse(handle)
There was a problem hiding this comment.
All those examples open the file in text mode, giving unicode string handles - not bytes handles.
There was a problem hiding this comment.
Exactly. These should all be opening the file in binary mode. The call to _as_bytes obscures this.
There was a problem hiding this comment.
Could we leave this as is for now, merge this pull request, and then let you tackle this? It seems a bit much to ask @Andrey-Raspopov to do it here.
There was a problem hiding this comment.
I've removed version >= 3, since it'll be >= 3 anyway. Also I've changed initial commentary to TODO, since it definitely looks like a work for another PR, but also it looks like a work that should be done. I can do that after we are finished with py3k or I can leave to it to @mdehoon.
There was a problem hiding this comment.
I can handle Bio.Entrez but please discard all changes to Bio.Entrez (and any other module still under discussion) from this pull request.
|
As @mdehoon points out, almost all the old occurrences of |
|
Yes using |
|
But using encode on byte string won't work, so as far as I understand we can change this type of behaviour only when we know that we expect string, not bytestring? Also, original as_bytes uses latin_1 and will fail on other literals, what kind of behaviour do we want to have here? |
…2420-strings � Conflicts: � Bio/Blast/NCBIWWW.py � Bio/SearchIO/_index.py � Bio/SeqIO/_index.py
|
Yes, the original There are only a few uses left (most were replaced by bytes literals), so we ought to be able to determine the expected input. (This is probably the hardest part of the whole |
…2420-strings � Conflicts: � Bio/SearchIO/BlatIO.py � Bio/SearchIO/ExonerateIO/exonerate_text.py � Bio/SearchIO/ExonerateIO/exonerate_vulgar.py � Bio/SeqIO/AbiIO.py � Bio/_py3k/__init__.py � Bio/bgzf.py
This usage dates back to when Biopython supported Python 2.5 which did not allow the simpler b"example" syntax. Squashed commit of changes cherry-picked from pull request biopython#2445.
This usage dates back to when Biopython supported Python 2.5 which did not allow the simpler b"example" syntax. Squashed commit of changes cherry-picked from pull request #2445.
|
Do you want me to squash this to a single commit and rebase it against the current master to deal with the conflicts, and make it easier to see where things stand? |
|
Yes, that would be good, I'll get back to this PR tomorrow morning. |
|
I've cherry-picked a couple more small edits to the master. I think that it might be best to start again - tackling things like This time don't add or move anything to |
|
Okay, I'll delete this branch then and will make new PR, much less messy:) |
This pull request addresses issue #2420
Note: I've decided to split this issue into several PRs, since it should be easier to review it. If that's not the case, I can first merge my remaining PRs into one.
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.rstfile, have runflake8locally, andunderstand 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.rstandCONTRIB.rstas part of this pull request, am listedalready, or do not wish to be listed. (This acknowledgement is optional.)