Skip to content

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

Closed

Description

@petruchio
mannequin
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']

    Activity

    1. petruchio commented on Mar 18, 2009

      petruchiomannequin
      MannequinAuthor

      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?

    2. added
      stdlib
      type-feature
      on Mar 18, 2009
    3. briancurtin commented on Jul 24, 2009

      @briancurtin
      Member

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

    4. ezio-melotti commented on Jul 24, 2009

      @ezio-melotti
      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.

    5. briancurtin commented on Jul 26, 2009

      @briancurtin
      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.

    6. ezio-melotti commented on Sep 12, 2009

      @ezio-melotti
      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.

    7. briancurtin commented on Oct 8, 2009

      @briancurtin
      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.

    8. ezio-melotti commented on Dec 30, 2009

      @ezio-melotti
      Member

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

    9. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    stdlibtype-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions