Skip to content
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

zipfile - add __exit__ attribute to make ZipFile object compatible with with_statement #49761

Closed
petruchio mannequin opened this issue Mar 18, 2009 · 7 comments
Closed
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@petruchio
Copy link
Mannequin

petruchio mannequin commented Mar 18, 2009

BPO 5511
Nosy @ezio-melotti, @briancurtin
Files
  • issue5511_complete.patch: code, test, and doc changes
  • issue5511_complete_20091008.patch: Added close tests per Ezio's suggestion
  • 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 = <Date 2009-12-30.13:55:28.187>
    created_at = <Date 2009-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 = <Date 2009-12-30.13:55:28.160>
    user = 'https://bugs.python.org/petruchio'

    bugs.python.org fields:

    activity = <Date 2009-12-30.13:55:28.160>
    actor = 'ezio.melotti'
    assignee = 'ezio.melotti'
    closed = True
    closed_date = <Date 2009-12-30.13:55:28.187>
    closer = 'ezio.melotti'
    components = ['Library (Lib)']
    creation = <Date 2009-03-18.18:24:22.081>
    creator = 'petruchio'
    dependencies = []
    files = ['14566', '15082']
    hgrepos = []
    issue_num = 5511
    keywords = ['patch']
    message_count = 7.0
    messages = ['83768', '90869', '90870', '90932', '92554', '93746', '97030']
    nosy_count = 3.0
    nosy_names = ['ezio.melotti', 'brian.curtin', 'petruchio']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue5511'
    versions = ['Python 2.7', 'Python 3.2']

    @petruchio
    Copy link
    Mannequin Author

    petruchio mannequin commented 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?

    @petruchio petruchio mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Mar 18, 2009
    @briancurtin
    Copy link
    Member

    Submitted a patch against trunk. Let me know if you need anything else
    (doc patch?).

    @ezio-melotti
    Copy link
    Member

    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
    Copy link
    Member

    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
    Copy link
    Member

    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
    Copy link
    Member

    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
    Copy link
    Member

    Done in r77136 (trunk) and r77142 (py3k). Thanks for the patch!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants