8000 gh-133982: Run unclosed file test on all io implementations by cmaloney · Pull Request #134165 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-133982: Run unclosed file test on all io implementations #134165

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
May 21, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Rely on IOBase __del__ implementation in FileIO
The FileIO one now matches all the others, so can use IOBase. There was
a missing check on closing (self._fd must be valid), add that check
  • Loading branch information
cmaloney committed May 18, 2025
commit 704bf460f2891d02f102238a6b27e3c1e7e40060
7 changes: 1 addition & 6 deletions Lib/_pyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1613,11 +1613,6 @@ def _dealloc_warn(self, source):
warnings.warn(f'unclosed file {source!r}', ResourceWarning,
stacklevel=2, source=self)

def __del__(self):
if self._fd >= 0 and self._closefd and not self.closed:
self._dealloc_warn(self)
self.close()

def __getstate__(self):
raise TypeError(f"cannot pickle {self.__class__.__name__!r} object")

Expand Down Expand Up @@ -1791,7 +1786,7 @@ def close(self):
if not self.closed:
self._stat_atopen = None
try:
if self._closefd:
if self._closefd and self._fd >= 0:
os.close(self._fd)
finally:
super().close()
Expand Down
Loading
0