defnull / multipart

A fast multipart/form-data parser for python
MIT License
126 stars 33 forks source link

Fix ResourceWarnings on Python 3 #21

Closed cjwatson closed 4 years ago

cjwatson commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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