Skip to content

Commit d457a3b

Browse files
committed
Add support for opener in open()
- needed to support tempfile in Python 3.11 - fixes #686
1 parent 5f59b09 commit d457a3b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ The released versions correspond to PyPi releases.
33

44
## Unreleased
55

6+
### Fixes
7+
* added support for `opener` argument in `open`, which is used in `tempfile`
8+
in Python 3.11 since beta 4 (see [#686](../../issues/686))
9+
610
## [Version 4.6.0](https://pypi.python.org/pypi/pyfakefs/4.6.0) (2022-07-12)
711
Adds support for Python 3.11, removes support for Python 3.6, changes root
812
path behavior under Windows.

pyfakefs/fake_filesystem.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5719,7 +5719,9 @@ def call(self, file_: Union[AnyStr, int],
57195719
closefd: If a file descriptor rather than file name is passed,
57205720
and this is set to `False`, then the file descriptor is kept
57215721
open when file is closed.
5722-
opener: not supported.
5722+
opener: an optional function object that will be called with
5723+
`file_` and the open flags (derived from `mode`) and returns
5724+
a file descriptor.
57235725
open_modes: Modes for opening files if called from low-level API.
57245726
57255727
Returns:
@@ -5741,6 +5743,11 @@ def call(self, file_: Union[AnyStr, int],
57415743

57425744
newline, open_modes = self._handle_file_mode(mode, newline, open_modes)
57435745

5746+
if opener is not None:
5747+
# opener shall return a file descriptor, which will be handled
5748+
# here as if directly passed
5749+
file_ = opener(file_, open_modes)
5750+
57445751
file_object, file_path, filedes, real_path = self._handle_file_arg(
57455752
file_)
57465753
if file_object is None and file_path is None:

0 commit comments

Comments
 (0)