Skip to content

Commit cd7d62c

Browse files
committed
Adapt to Python 3.14 alpha 5
- do not patch globber.scandir in 3.14 - switch off copy file range optimization (Linux only)
1 parent e8ae593 commit cd7d62c

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

.github/workflows/testsuite.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ jobs:
3232
fail-fast: false
3333
matrix:
3434
os: [ubuntu-latest, macOS-latest, windows-latest]
35-
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
36-
# python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13", "3.14"]
35+
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13", "3.14"]
3736
include:
3837
- python-version: "pypy-3.7"
3938
os: ubuntu-22.04

pyfakefs/fake_filesystem_unittest.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,8 @@ def __init__(
689689
self._dyn_patcher: Optional[DynamicPatcher] = None
690690
self._patching = False
691691
self._paused = False
692+
self.has_copy_file_range = False
693+
self.has_copy_file = False
692694

693695
def checkcache(self, filename=None):
694696
"""Calls the original linecache.checkcache making sure no fake OS calls
@@ -990,6 +992,14 @@ def setUp(self, doctester: Any = None) -> None:
990992
if self.has_fcopy_file:
991993
shutil._HAS_FCOPYFILE = False # type: ignore[attr-defined]
992994

995+
self.has_copy_file_range = (
996+
sys.platform == "linux"
997+
and hasattr(shutil, "_USE_CP_COPY_FILE_RANGE")
998+
and shutil._USE_CP_COPY_FILE_RANGE
999+
)
1000+
if self.has_copy_file_range:
1001+
shutil._USE_CP_COPY_FILE_RANGE = False # type: ignore[attr-defined]
1002+
9931003
# do not use the fd functions, as they may not be available in the target OS
9941004
if hasattr(shutil, "_use_fd_functions"):
9951005
shutil._use_fd_functions = False # type: ignore[module-attr]
@@ -1047,7 +1057,8 @@ def _set_glob_os_functions(self):
10471057
if sys.version_info >= (3, 13):
10481058
globber = glob._StringGlobber # type: ignore[module-attr]
10491059
globber.lstat = staticmethod(os.lstat)
1050-
globber.scandir = staticmethod(os.scandir)
1060+
if sys.version_info < (3, 14):
1061+
globber.scandir = staticmethod(os.scandir)
10511062

10521063
def patch_functions(self) -> None:
10531064
assert self._stubs is not None
@@ -1124,6 +1135,8 @@ def tearDown(self, doctester: Any = None):
11241135
self.stop_patching()
11251136
if self.has_fcopy_file:
11261137
shutil._HAS_FCOPYFILE = True # type: ignore[attr-defined]
1138+
if self.has_copy_file_range:
1139+
shutil._USE_CP_COPY_FILE_RANGE = True # type: ignore[attr-defined]
11271140

11281141
reset_ids()
11291142
if self.is_doc_test:

0 commit comments

Comments
 (0)