Skip to content

bpo-37523: Raise ValueError for I/O operations on a closed zipfile.ZipExtFile #14658

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

Merged
merged 2 commits into from
Nov 30, 2019

Conversation

danifus
Copy link
Contributor

@danifus danifus commented Jul 9, 2019

Raises ValueErrorwhen calling the following on a closed zipfile.ZipExtFile:

  • read
  • readable
  • seek
  • seekable
  • tell

https://bugs.python.org/issue37523

…pExtFile

Raises `ValueError`when calling the following on a closed
`zipfile.ZipExtFile`:
- `read`
- `readable`
- `seek`
- `seekable`
- `tell`
@mangrisano
Copy link
Contributor

I think the news can be skipped.

@danifus
Copy link
Contributor Author

danifus commented Jul 9, 2019

Ok, I've removed the news but I'm unsure of how to apply the "skip news" label. Thanks for the review

@mangrisano
Copy link
Contributor

Unfortunately we can't because we don't have the right permissions on the repo. Anyway, after removing the news file, the tests that before this operation failed now are ok.

Thank you :)

Copy link
Contributor

@mangrisano mangrisano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@danifus
Copy link
Contributor Author

danifus commented Jul 9, 2019

Ah that explains why I couldn't find the add label button!

Thanks again for the review :)

@aeros
Copy link
Contributor

aeros commented Jul 9, 2019

Ok, I've removed the news but I'm unsure of how to apply the "skip news" label. Thanks for the review

The skip news label can currently only be applied by the core devs. There's a proposal in place to allow for the triagers to also be able to do this, but contributors can't add those labels. If you don't think your particular PR needs the news item, just leave it out and a core dev will let you know whether or not it's needed when they review it.

Copy link
Contributor

@aeros aeros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danifus Thanks for the contribution! I like the idea of adding tests to ensure that ValueErrors are appropriately raised for zipfiles, but I had some suggestions.

To make this change a bit more scale-able (in case other exceptions are added to the tests), I would recommend changing lines 575-582 to something like this:

with zipfile.ZipFile(TESTFN2, mode="r") as zipfp:
    with zipfp.open(fname) as fid:
        fid.close()
        for function, *args in [fid.read, fid.tell, fid.readable, fid.seekable, 
        fid.extract, fid.testzip, fid.write, (fid.seek, 0)]:
            self.assertRaises(ValueError, function, *args)

Functionally, this operates the same, but is a bit more readable and easy to add additional functions to test simply by adding another one at the end of the list. Also, seek() already defaults to 0, so there's no need to specify it explicitly (https://docs.python.org/3.9/library/io.html#io.IOBase.seek).

Edit: Corrected seek() and added other functions, mostly as scale-ability example, not for specifically adding each of those functions to the PR.

Edit2: Remembered a way to include a variable number of arguments to unpack, added it to the example.

@danifus
Copy link
Contributor Author

danifus commented Jul 9, 2019

Thanks for the suggestions @aeros167. seek does require the offset parameter to be supplied (seek(offset[, whence])) and I prefer having them written out explicitly in this instance.

@aeros
Copy link
Contributor

aeros commented Jul 9, 2019

Thanks for the suggestions @aeros167. seek does require the offset parameter to be supplied (seek(offset[, whence])) and I prefer having them written out explicitly in this instance.

@danifus

Edit: I've changed my stance on the testing guidelines since I first wrote this review several months ago. It's not much of an issue repeat 5 lines for the tests instead of using iteration, that comes down more to styling preference and prior precedence in the existing format of the other tests in the file. I added @serhiy-storchaka as a reviewer for this PR, since he's an active core dev with expertise in the zipfile module.

@brettcannon brettcannon added the type-feature A feature request or enhancement label Jul 11, 2019
@aeros aeros requested a review from serhiy-storchaka October 2, 2019 09:38
@serhiy-storchaka serhiy-storchaka merged commit 8d62df6 into python:master Nov 30, 2019
jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
…pExtFile. (pythonGH-14658)

Raises ValueError when calling the following on a closed zipfile.ZipExtFile: read, readable, seek, seekable, tell.
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
…pExtFile. (pythonGH-14658)

Raises ValueError when calling the following on a closed zipfile.ZipExtFile: read, readable, seek, seekable, tell.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants