]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
tests: use errno.EBADF instead of hardcoded number in _close_file() (GH-148345)
authorArtem Yarulin <artem.yarulin@kapteko.com>
Sun, 12 Apr 2026 00:01:18 +0000 (03:01 +0300)
committerGitHub <noreply@github.com>
Sun, 12 Apr 2026 00:01:18 +0000 (17:01 -0700)
test_interpreters: use errno.EBADF instead of hardcoded number in _close_file()

Replace the hardcoded `9` check in `Lib/test/test_interpreters/utils.py` with `errno.EBADF`.

Using `errno.EBADF` makes the helper portable across platforms with different errno numbering while preserving the intended behavior.

Lib/test/test_interpreters/utils.py

index ae09aa457b48c7a9a55fcf24de19deca63e067f3..bb6da52727c2128ac7eb07efedf9a4c2fb51b00b 100644 (file)
@@ -1,5 +1,6 @@
 from collections import namedtuple
 import contextlib
+import errno
 import json
 import logging
 import os
@@ -51,7 +52,7 @@ def _close_file(file):
         else:
             os.close(file)
     except OSError as exc:
-        if exc.errno != 9:
+        if exc.errno != errno.EBADF:
             raise  # re-raise
         # It was closed already.