-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SeqIO.parse side effects #4252
Comments
Cross reference #4251 So you want to enable the SeqIO iterating parsers to be used as context managers? Perhaps adding the methods to the base class would be enough... I'm not going to find time to work on this soon (and don't fully understand your motivating use case), but would be happy to review a PR if you wanted to do this. |
Yes I think so.
I don't think it's a major issue; it's just that Biopython is deviating from Python's approach. If flake or black could detect such issues, it would be flagged as an error. Let's keep this PR open until somebody find time to fix this. |
@BabaYaga1221 In |
There is some inconsistency in exception handling between Python and Biopython when parsing files.
This is what happens in Python (using the binary file
310.ab1
inTests/Abi
as an example):i.e. the file stream stays open.
Biopython's
SeqIO.parse
, on the other hand, closes the file if an exception occurs:Python will close the file if a
with
-block is used:However, this is currently not supported by Biopython:
To be consistent with Python, Biopython should keep the file stream open if an exception occurs.
To ensure that file streams get closed if an exception occur,
__enter__
,__exit__
methods can be added to theSeqIO
iterator to supportwith
blocks.The text was updated successfully, but these errors were encountered: