Repository navigation
Python 3 updates for SFF support and tests - #2499
Conversation
This is part of issue biopython#2490
The existing method for checking text vs binary mode needed a substantial rewrite for Python 3, and this way is simpler and more pythonic.
Codecov Report
@@ Coverage Diff @@
## master #2499 +/- ##
==========================================
+ Coverage 84.77% 84.94% +0.16%
==========================================
Files 322 322
Lines 52437 53234 +797
==========================================
+ Hits 44456 45217 +761
- Misses 7981 8017 +36
Continue to review full report at Codecov.
|
| data = handle.read(31) | ||
| if not data: | ||
| raise ValueError("Empty file.") | ||
| elif isinstance(data, str): |
There was a problem hiding this comment.
The pythonic way would be to call struct.unpack(fmt, data) below in a try: except: block. struct.unpack will raise a TypeError if data is not a bytes-like object. Then you don't need to use isinstance here.
| handle.close() | ||
| return StringIO(data.decode()) | ||
| """Open gzip file in either binary or text mode as needed.""" | ||
| if format in SeqIO._BinaryFormats: |
There was a problem hiding this comment.
Some day we should try and get rid of SeqIO._BinaryFormats
There was a problem hiding this comment.
Yes, and this pull request is a small step in that direction.
mdehoon
left a comment
There was a problem hiding this comment.
Other than my comment on _sff_file_header, I am OK with this.
| except TypeError: | ||
| # Good, we wanted a binary handle: | ||
| # e.g. TypeError: a bytes-like object is required, not 'str' | ||
| pass |
There was a problem hiding this comment.
Actually here you could use handle.write(b"") to explicitly test if the handle was opened in binary mode.
There was a problem hiding this comment.
I didn't think of that - almost but not quite a NOP (no operation), that does seem more elegant.
Thank you to Michiel de Hoon.
|
Thank you - your input definitely improved this. |
This pull request addresses in part issue #2490.
See also discussion on #2496.
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.)