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

Fix ResourceWarnings on Python 3 #21

Merged
merged 1 commit into from
Sep 4, 2020

Conversation

cjwatson
Copy link
Collaborator

@cjwatson cjwatson commented Aug 2, 2020

Add a MultipartPart.close method, which consumers can use to close files
(if any) when they're finished with them. Call it on some error paths
when parts are about to go out of scope, avoiding ResourceWarnings in
the test suite.

Also use a context manager in MultipartPart.save_as to avoid another
more straightforward ResourceWarning.

Add a MultipartPart.close method, which consumers can use to close files
(if any) when they're finished with them.  Call it on some error paths
when parts are about to go out of scope, avoiding ResourceWarnings in
the test suite.

Also use a context manager in MultipartPart.save_as to avoid another
more straightforward ResourceWarning.
@defnull
Copy link
Owner

defnull commented Aug 3, 2020

Looks good to me. I'll need to check with a bit more time at hand, but I think this can be merged and released without any deprecation warning phase. It is unlikely that someone expects a part to be readable after an error condition.

@cjwatson
Copy link
Collaborator Author

cjwatson commented Aug 3, 2020

In particular I believe that, in all the cases I touched, the part in question is literally inaccessible by callers - it hasn't yet been yielded or returned.

cjwatson added a commit to cjwatson/zope.publisher that referenced this pull request Aug 4, 2020
This currently adds ResourceWarnings on Python 3; that will be fixed
when defnull/multipart#21 lands.

Fixes zopefoundation#39.
@cjwatson
Copy link
Collaborator Author

cjwatson commented Sep 2, 2020

Hi - would it be possible to look at this fairly soon? I think my PR to convert zope.publisher to multipart (zopefoundation/zope.publisher#55) is otherwise ready to land, but it would be a bit of a shame to land it in a state that adds ResourceWarnings.

@defnull defnull merged commit 65c6c53 into defnull:master Sep 4, 2020
@defnull
Copy link
Owner

defnull commented Sep 4, 2020

Thanks for the reminder! I just merged this and released version 0.2.2 to pypi.

@cjwatson cjwatson deleted the resource-warnings branch October 30, 2020 14:01
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.

2 participants