Repository navigation
Conversation
|
I can confirm that this fixes the warning for me. |
|
Good catch, @taldcroft ; need a change log as this is labeled a bug! Are the @bsipocz , I'll let you milestone it. Thinking either 3.2 or 3.2.1 but no point porting to 2.x series. |
|
I milestoned this for 3.2.1. It's not really a critical bug and we do need to have someone that actually understands the code have a close look to be sure this fix does not have unintended consequences. |
|
Looking at this more, I am not so sure. So, it turns out your use case was a nested Before this patch: >>> with get_readable_fileobj(filename, encoding='binary') as fileobj:
... with get_readable_fileobj(fileobj, encoding='UTF-8') as fileobj2:
.... out = fileobj2.seek(1)
... print(fileobj.closed, fileobj2.closed)
... print(fileobj.closed, fileobj2.closed)
False False
True TrueWith this patch: >>> with get_readable_fileobj(filename, encoding='binary') as fileobj:
... with get_readable_fileobj(fileobj, encoding='UTF-8') as fileobj2:
.... out = fileobj2.seek(1)
... print(fileobj.closed, fileobj2.closed)
... print(fileobj.closed, fileobj2.closed)
True True
True TrueSo, with this patch, the following is now broken: >>> with get_readable_fileobj(filename, encoding='binary') as fileobj:
... with get_readable_fileobj(fileobj, encoding='UTF-8') as fileobj2:
... out = fileobj2.seek(1)
... out = fileobj.seek(1)
ValueError: I/O operation on closed filewhich seems wrong to me because technically |
|
Thanks @pllim looks like you quickly found the unintended consequences! And as a by-product we have a new regression test that can be added to the So the problem may really be in |
|
I think the cause of the |
This one-line change addresses what I found in #8673 (comment). But to be totally honest I have no idea if this is messing anything else up. Tossing this up as a PR to see if it passes all tests (locally passed Table and all astropy/io tests).
@timj - could you confirm this removes the ResourceWarning for you?
Fixes #8673.