Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-131492: gh-131461: handle exceptions in GzipFile constructor while owning resources #131462

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 20 commits into from
Mar 20, 2025

Conversation

graingert
Copy link
Contributor

@graingert graingert commented Mar 19, 2025

@graingert graingert marked this pull request as ready for review March 19, 2025 14:28
@graingert graingert requested a review from vstinner March 19, 2025 14:38
@vstinner
Copy link
Member

@cmaloney: Would you mind to review this fix?

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Would it be possible to write a test with such broken file object?

@graingert graingert requested a review from ethanfurman as a code owner March 19, 2025 16:31
@graingert
Copy link
Contributor Author

Would it be possible to write a test with such broken file object?

There's already a test in test_tarfile: test_open_nonwritable_fileobj the failure will be enforced by #128973

I added check_no_resource_warning to make the assert hold until then

graingert and others added 2 commits March 19, 2025 17:10
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@vstinner
Copy link
Member

The CI fails:

TypeError: check_no_resource_warning() missing 1 required positional argument: 'testcase'

Co-authored-by: Victor Stinner <[email protected]>
@graingert
Copy link
Contributor Author

The CI fails:

TypeError: check_no_resource_warning() missing 1 required positional argument: 'testcase'

🤦

@graingert graingert changed the title gh-131461: fix ResourceWarning when writing a unwritable gzipfile gh-131492: gh-131461: fix ResourceWarning when writing a unwritable gzipfile Mar 20, 2025
@graingert graingert added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Mar 20, 2025
@graingert graingert changed the title gh-131492: gh-131461: fix ResourceWarning when writing a unwritable gzipfile gh-131492: gh-131461: handle exceptions in GzipFile constructor while owning resources Mar 20, 2025
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM.

I would add support.gc_collect() in tests.

@vstinner vstinner enabled auto-merge (squash) March 20, 2025 16:49
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@vstinner vstinner merged commit ce79274 into python:main Mar 20, 2025
39 checks passed
@miss-islington-app
Copy link

Thanks @graingert for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 20, 2025
…ructor while owning resources (pythonGH-131462)

(cherry picked from commit ce79274)

Co-authored-by: Thomas Grainger <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Mar 20, 2025

GH-131518 is a backport of this pull request to the 3.13 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 20, 2025
…ructor while owning resources (pythonGH-131462)

(cherry picked from commit ce79274)

Co-authored-by: Thomas Grainger <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Mar 20, 2025
@bedevere-app
Copy link

bedevere-app bot commented Mar 20, 2025

GH-131519 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Mar 20, 2025
@vstinner
Copy link
Member

Hum, the backports mention ResourceWarning, whereas ResourceWarning only exists in Python 3.14. If we want to backport this change to 3.13 and 3.12, maybe references to ResourceWarning should be removed?

What do you think @graingert?

@graingert
Copy link
Contributor Author

graingert commented Mar 20, 2025

Oh yeah nix the 3.14 specific bits of the changelog from the backports

@graingert graingert deleted the fix-resource-warning-in-gzipfile-ctor branch March 20, 2025 17:35
@graingert
Copy link
Contributor Author

I've removed the references to a ResourceWarning in the backports

vstinner added a commit that referenced this pull request Mar 21, 2025
…r while owning resources (GH-131462) (#131518)

(cherry picked from commit ce79274)

Co-authored-by: Thomas Grainger <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
vstinner added a commit that referenced this pull request Mar 21, 2025
…r while owning resources (GH-131462) (#131519)

(cherry picked from commit ce79274)

Co-authored-by: Thomas Grainger <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
…ructor while owning resources (python#131462)

Co-authored-by: Victor Stinner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants