https://github.com/python/cpython/commit/8d7d257f6bcc76892a084b169cc9efa414a9e4c6
commit: 8d7d257f6bcc76892a084b169cc9efa414a9e4c6
branch: main
author: Michał Górny <[email protected]>
committer: vstinner <[email protected]>
date: 2024-10-02T14:31:42Z
summary:
gh-124213: Fix incorrect context manager use in
in_systemd_nspawn_sync_suppressed() (#124892)
Fix the incorrect use of `os.open()` result as a context manager,
while it is actually a numeric file descriptor.
I have missed the problem, because in the original version the
`os.open()` call would always fail, and I failed to test the final
version in all possible scenarios properly.
files:
M Lib/test/support/__init__.py
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 99cb10fc7b5f7b..1a44cc638b5714 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2907,10 +2907,11 @@ def in_systemd_nspawn_sync_suppressed() -> bool:
# trigger EINVAL. Otherwise, ENOENT will be given instead.
import errno
try:
- with os.open(__file__, os.O_RDONLY | os.O_SYNC):
- pass
+ fd = os.open(__file__, os.O_RDONLY | os.O_SYNC)
except OSError as err:
if err.errno == errno.EINVAL:
return True
+ else:
+ os.close(fd)
return False
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]