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
{{ message }}
Repository navigation
zipfile - add __exit__ attribute to make ZipFile object compatible with with_statement #49761
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/ezio-melotti'closed_at=<Date2009-12-30.13:55:28.187>created_at=<Date2009-03-18.18:24:22.081>labels= ['type-feature', 'library']
title='zipfile - add __exit__ attribute to make ZipFile object compatible with with_statement'updated_at=<Date2009-12-30.13:55:28.160>user='https://bugs.python.org/petruchio'
Currently the zipfile.ZipFile class has no __exit__ atribute, so it
does not work with a with statement as other file objects do. Can this
be implemented?
I think there should also be one or more tests that check if the file is
closed correctly after the __exit__, in normal conditions and possibly
in different situations (e.g. when an error is raised ).
Unlike regular file objects, ZipFile objects don't have a 'closed'
attribute, instead they set self.fp to None when the 'close' method is
called.
Activity
petruchio commentedon Mar 18, 2009
Currently the zipfile.ZipFile class has no __exit__ atribute, so it
does not work with a with statement as other file objects do. Can this
be implemented?
briancurtin commentedon Jul 24, 2009
Submitted a patch against trunk. Let me know if you need anything else
(doc patch?).
ezio-melotti commentedon Jul 24, 2009
It would be nice if you could provide unit tests.
If you can also provide a patch for the doc, it's even better.
briancurtin commentedon Jul 26, 2009
Attached is a patch containing the fix, the updated tests, and the doc
change. Let me know if you have any questions, suggestions, etc.
ezio-melotti commentedon Sep 12, 2009
I think there should also be one or more tests that check if the file is
closed correctly after the __exit__, in normal conditions and possibly
in different situations (e.g. when an error is raised ).
Unlike regular file objects, ZipFile objects don't have a 'closed'
attribute, instead they set self.fp to None when the 'close' method is
called.
briancurtin commentedon Oct 8, 2009
Added two tests -- test_close and test_close_on_exception, which check
if fp is None after __exit__ from a normal and exception case.
ezio-melotti commentedon Dec 30, 2009
Done in r77136 (trunk) and r77142 (py3k). Thanks for the patch!