File tree Expand file tree Collapse file tree 3 files changed +14
-21
lines changed Expand file tree Collapse file tree 3 files changed +14
-21
lines changed Original file line number Diff line number Diff line change 33
33
34
34
from pyfakefs .fake_file import AnyFileWrapper
35
35
from pyfakefs .fake_open import fake_open
36
- from pyfakefs .helpers import IS_PYPY
36
+ from pyfakefs .helpers import IS_PYPY , is_called_from_skipped_module
37
37
38
38
if TYPE_CHECKING :
39
39
from pyfakefs .fake_filesystem import FakeFilesystem
@@ -180,6 +180,14 @@ def lockf(
180
180
) -> Any :
181
181
pass
182
182
183
- def __getattr__ (self , name ):
183
+ def __getattribute__ (self , name ):
184
184
"""Forwards any unfaked calls to the standard fcntl module."""
185
- return getattr (self ._fcntl_module , name )
185
+ filesystem = object .__getattribute__ (self , "filesystem" )
186
+ fnctl_module = object .__getattribute__ (self , "_fcntl_module" )
187
+ if filesystem .patcher :
188
+ skip_names = filesystem .patcher ._skip_names
189
+ if is_called_from_skipped_module (skip_names = skip_names ):
190
+ # remove the `self` argument for FakeOsModule methods
191
+ return getattr (fnctl_module , name )
192
+
193
+ return object .__getattribute__ (self , name )
Original file line number Diff line number Diff line change 44
44
)
45
45
from pyfakefs .helpers import (
46
46
AnyString ,
47
+ is_called_from_skipped_module ,
47
48
is_root ,
48
49
PERM_READ ,
49
50
PERM_WRITE ,
@@ -83,23 +84,7 @@ def fake_open(
83
84
"""Redirect the call to FakeFileOpen.
84
85
See FakeFileOpen.call() for description.
85
86
"""
86
- # workaround for built-in open called from skipped modules (see #552)
87
- # as open is not imported explicitly, we cannot patch it for
88
- # specific modules; instead we check if the caller is a skipped
89
- # module (should work in most cases)
90
- stack = traceback .extract_stack (limit = 3 )
91
- # handle the case that we try to call the original `open_code`
92
- # and get here instead (since Python 3.12)
93
- from_open_code = (
94
- sys .version_info >= (3 , 12 )
95
- and stack [0 ].name == "open_code"
96
- and stack [0 ].line == "return self._io_module.open_code(path)"
97
- )
98
- module_name = os .path .splitext (stack [0 ].filename )[0 ]
99
- module_name = module_name .replace (os .sep , "." )
100
- if from_open_code or any (
101
- [module_name == sn or module_name .endswith ("." + sn ) for sn in skip_names ]
102
- ):
87
+ if is_called_from_skipped_module (skip_names = skip_names ):
103
88
return io .open ( # pytype: disable=wrong-arg-count
104
89
file ,
105
90
mode ,
Original file line number Diff line number Diff line change @@ -449,7 +449,7 @@ def is_called_from_skipped_module(skip_names: list) -> bool:
449
449
(
450
450
frame .filename
451
451
for frame in stack [::- 1 ]
452
- if not frame .filename .startswith ("<frozen importlib " )
452
+ if not frame .filename .startswith ("<frozen " )
453
453
and not frame .filename .startswith (STDLIB_PATH )
454
454
and (
455
455
not frame .filename .startswith (PYFAKEFS_PATH )
You can’t perform that action at this time.
0 commit comments