Skip to content

Bug: FakeFileOpen objects don't implement the mode property required by typing.io.IO #1162

Closed
@evgenii-moriakhin

Description

@evgenii-moriakhin

How To Reproduce

from pyfakefs.fake_filesystem import FakeFilesystem
from pyfakefs.fake_open import FakeFileOpen
from pyfakefs.fake_pathlib import FakePathlibModule

fake_fs = FakeFilesystem()
fake_open = FakeFileOpen(fake_fs)
fake_pathlib = FakePathlibModule(fake_fs)

f = open("test.txt")
assert f.mode  # This works fine

fake_pathlib.Path("test.txt").write_text(f.read())
f_ = fake_open("test.txt")
assert f_.mode  # This fails

Expected behavior:
Fake file objects should properly implement the mode property as required by the typing.io.IO abstract class:

class IO(Generic[AnyStr]):
    @property
    @abstractmethod
    def mode(self) -> str:
        pass

Your environment
python3.9
pyfakefs==5.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions