Repository: biopython/biopython

Issue:
Binary format
This pull request addresses issue #2332

<!--- Please read each of the following items and confirm by replacing
 !--the [ ] with a [X] --->

- [X] I hereby agree to dual licence this and any previous contributions under both
the _Biopython License Agreement_ **AND** the _BSD 3-Clause License_.

- [X] 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.

- [X] 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.*)



Discussion:
# [Codecov](https://codecov.io/gh/biopython/biopython/pull/2333?src=pr&el=h1) Report
> Merging [#2333](https://codecov.io/gh/biopython/biopython/pull/2333?src=pr&el=desc) into [master](https://codecov.io/gh/biopython/biopython/commit/d362e1bf54f23a4e2bc94896b039ebbba034d5e3?src=pr&el=desc) will **increase** coverage by `0.03%`.
> The diff coverage is `62.5%`.

[![Impacted file tree graph](https://codecov.io/gh/biopython/biopython/pull/2333/graphs/tree.svg?width=650&token=x1lNrIYszs&height=150&src=pr)](https://codecov.io/gh/biopython/biopython/pull/2333?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #2333      +/-   ##
==========================================
+ Coverage   84.94%   84.98%   +0.03%     
==========================================
  Files         323      323              
  Lines       52622    52726     +104     
==========================================
+ Hits        44702    44810     +108     
+ Misses       7920     7916       -4
```


| [Impacted Files](https://codecov.io/gh/biopython/biopython/pull/2333?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [Bio/SeqRecord.py](https://codecov.io/gh/biopython/biopython/pull/2333/diff?src=pr&el=tree#diff-QmlvL1NlcVJlY29yZC5weQ==) | `92.63% <62.5%> (-1.07%)` | :arrow_down: |
| [Bio/bgzf.py](https://codecov.io/gh/biopython/biopython/pull/2333/diff?src=pr&el=tree#diff-QmlvL2JnemYucHk=) | `96.42% <0%> (+4%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/biopython/biopython/pull/2333?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/biopython/biopython/pull/2333?src=pr&el=footer). Last update [d362e1b...ae4d9fe](https://codecov.io/gh/biopython/biopython/pull/2333?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Applied, as discussed above we can revisit this after dropping Python 2 (not long to wait now).

Resolving patch:
diff --git a/Bio/SeqRecord.py b/Bio/SeqRecord.py
--- a/Bio/SeqRecord.py
+++ b/Bio/SeqRecord.py
@@ -749,23 +749,10 @@ def __format__(self, format_spec):
             return SeqIO._FormatToString[format_spec](self)
 
         if format_spec in SeqIO._BinaryFormats:
-            import sys
-
-            if sys.version_info[0] < 3:
-                import warnings
-                from Bio import BiopythonDeprecationWarning
-
-                warnings.warn(
-                    "Binary format %s cannot be used with SeqRecord format method on Python 3"
-                    % format_spec,
-                    BiopythonDeprecationWarning,
-                )
-                # Continue - Python 2 StringIO will work...
-            else:
-                raise ValueError(
-                    "Binary format %s cannot be used with SeqRecord format method"
-                    % format_spec
-                )
+            raise ValueError(
+                "Binary format %s cannot be used with SeqRecord format method"
+                % format_spec
+            )
 
         # Harder case, make a temp handle instead
         from Bio._py3k import StringIO


Test patch: