Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ repos:
- "--py310-plus"

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.15.11"
rev: "v0.16.0"
hooks:
- id: ruff
args: ["--fix"]
- id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.4.2
rev: v2.4.3
hooks:
- id: codespell
args:
Expand All @@ -44,7 +44,7 @@ repos:
language: python
files: \.py$
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.20.1
rev: v2.3.0
hooks:
- id: mypy
exclude: (docs|pyfakefs/tests)
25 changes: 12 additions & 13 deletions pyfakefs/fake_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,37 @@
import sys
import traceback
import weakref
from collections.abc import Callable, Iterator
from stat import (
S_IFREG,
S_IFDIR,
S_IFREG,
)
from types import TracebackType
from typing import (
Union,
TYPE_CHECKING,
Any,
cast,
AnyStr,
NoReturn,
TextIO,
TYPE_CHECKING,
Union,
cast,
)

from collections.abc import Callable, Iterator

from pyfakefs import helpers
from pyfakefs.helpers import (
FakeStatResult,
AnyPath,
AnyString,
BinaryBufferIO,
FakeStatResult,
TextBufferIO,
_OpenModes,
get_locale_encoding,
is_int_type,
is_root,
is_unicode_string,
to_string,
matching_string,
real_encoding,
AnyPath,
AnyString,
get_locale_encoding,
_OpenModes,
is_root,
to_string,
)

if TYPE_CHECKING:
Expand Down
37 changes: 18 additions & 19 deletions pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,42 +92,40 @@
import sys
import tempfile
import weakref
from collections import namedtuple, OrderedDict
from collections import OrderedDict, namedtuple
from collections.abc import Callable
from doctest import TestResults
from enum import Enum

from stat import (
S_IFREG,
S_IFDIR,
S_ISLNK,
S_IFLNK,
S_IFMT,
S_IFREG,
S_ISDIR,
S_IFLNK,
S_ISLNK,
S_ISREG,
)
from typing import (
TYPE_CHECKING,
Any,
cast,
AnyStr,
overload,
NoReturn,
TYPE_CHECKING,
cast,
overload,
)

from collections.abc import Callable

from pyfakefs import fake_file, fake_path, fake_io, fake_os, helpers, fake_open
from pyfakefs.fake_file import AnyFileWrapper, AnyFile
from pyfakefs import fake_file, fake_io, fake_open, fake_os, fake_path, helpers
from pyfakefs.fake_file import AnyFile, AnyFileWrapper
from pyfakefs.helpers import (
is_int_type,
make_string_path,
to_string,
matching_string,
POSIX_PROPERTIES,
WINDOWS_PROPERTIES,
AnyPath,
AnyString,
WINDOWS_PROPERTIES,
POSIX_PROPERTIES,
FSType,
is_int_type,
make_string_path,
matching_string,
to_string,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -2569,7 +2567,7 @@ def add_package_metadata(self, package_name: str) -> None:
Raises:
PackageNotFoundError: if the package with the given name is not found
"""
from importlib.metadata import distribution, PackageNotFoundError
from importlib.metadata import PackageNotFoundError, distribution

# we have to pause patching to get the distribution
# from the real filesystem if we are in patch mode
Expand Down Expand Up @@ -3296,6 +3294,7 @@ def _create_temp_dir(self):

def _run_doctest() -> TestResults:
import doctest

import pyfakefs

return doctest.testmod(pyfakefs.fake_filesystem)
Expand Down
2 changes: 1 addition & 1 deletion pyfakefs/fake_filesystem_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import os
import shutil
import sys
from threading import RLock
from collections.abc import Callable
from threading import RLock
from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand Down
38 changes: 22 additions & 16 deletions pyfakefs/fake_filesystem_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,36 @@
import unittest
import warnings
import weakref
from collections.abc import Callable, ItemsView, Iterator, Sequence
from importlib import reload
from importlib.abc import Loader, MetaPathFinder
from importlib.machinery import ModuleSpec
from importlib.util import spec_from_file_location, module_from_spec
from types import ModuleType, TracebackType, FunctionType
from importlib.util import module_from_spec, spec_from_file_location
from types import FunctionType, ModuleType, TracebackType
from typing import (
Any,
Optional,
cast,
)

from collections.abc import Callable, Iterator, ItemsView, Sequence
from unittest import TestSuite

from pyfakefs import fake_filesystem, fake_io, fake_os, fake_open, fake_path, fake_file
from pyfakefs import fake_filesystem_shutil
from pyfakefs import fake_pathlib
from pyfakefs import mox3_stubout
from pyfakefs import (
fake_file,
fake_filesystem,
fake_filesystem_shutil,
fake_io,
fake_open,
fake_os,
fake_path,
fake_pathlib,
mox3_stubout,
)
from pyfakefs.fake_filesystem import (
set_uid,
set_gid,
reset_ids,
PatchMode,
FakeFilesystem,
PatchMode,
reset_ids,
set_gid,
set_uid,
)
from pyfakefs.fake_os import use_original_os
from pyfakefs.helpers import IS_PYPY, IS_WIN
Expand Down Expand Up @@ -554,9 +560,9 @@ class Patcher:
SKIPMODULES.add(nt)
SKIPMODULES.add(ntpath)
else:
import fcntl
import posix
import posixpath
import fcntl

SKIPMODULES.add(posix)
SKIPMODULES.add(posixpath)
Expand Down Expand Up @@ -725,10 +731,10 @@ def __init__(

if use_known_patches:
from pyfakefs.patched_packages import (
get_modules_to_patch,
get_classes_to_patch,
get_fake_module_classes,
get_cleanup_handlers,
get_fake_module_classes,
get_modules_to_patch,
)

modules_to_patch = modules_to_patch or {}
Expand Down Expand Up @@ -1250,7 +1256,7 @@ def __enter__(self) -> FakeFilesystem:
self._fs.pause()
return self._fs

def __exit__(self, *args: Any) -> None:
def __exit__(self, *args: object) -> None:
self._fs.resume()


Expand Down
7 changes: 3 additions & 4 deletions pyfakefs/fake_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@
import _io # pytype: disable=import-error
import io
import sys
from collections.abc import Callable
from enum import Enum
from typing import (
Any,
AnyStr,
IO,
TYPE_CHECKING,
Any,
AnyStr,
)

from collections.abc import Callable

from pyfakefs.fake_file import AnyFileWrapper
from pyfakefs.fake_open import fake_open
from pyfakefs.helpers import IS_PYPY, is_called_from_skipped_module
Expand Down
22 changes: 11 additions & 11 deletions pyfakefs/fake_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,29 @@
S_ISDIR,
)
from typing import (
IO,
TYPE_CHECKING,
Any,
cast,
AnyStr,
TYPE_CHECKING,
IO,
cast,
)

from pyfakefs import helpers
from pyfakefs.fake_file import (
AnyFileWrapper,
FakeBinaryFileWrapper,
FakeTextFileWrapper,
FakePipeWrapper,
FakeFileWrapper,
FakeFile,
AnyFileWrapper,
FakeFileWrapper,
FakePipeWrapper,
FakeTextFileWrapper,
)
from pyfakefs import helpers
from pyfakefs.helpers import (
AnyString,
is_called_from_skipped_module,
is_root,
PERM_READ,
PERM_WRITE,
AnyString,
_OpenModes,
is_called_from_skipped_module,
is_root,
is_unfaked_path,
)

Expand Down
33 changes: 16 additions & 17 deletions pyfakefs/fake_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,47 @@
import os
import sys
import uuid
from collections.abc import Callable
from contextlib import contextmanager
from stat import (
S_IFREG,
S_IFSOCK,
)
from typing import (
TYPE_CHECKING,
Any,
cast,
AnyStr,
TYPE_CHECKING,
cast,
)

from collections.abc import Callable

from pyfakefs.fake_file import (
AnyFileWrapper,
FakeDirectory,
FakeDirWrapper,
StandardStreamWrapper,
FakeFile,
FakeFileWrapper,
FakePipeWrapper,
FakeFile,
AnyFileWrapper,
StandardStreamWrapper,
)
from pyfakefs.fake_open import FakeFileOpen, _OpenModes
from pyfakefs.fake_path import FakePathModule
from pyfakefs.fake_scandir import scandir, walk, ScanDirIter
from pyfakefs.fake_scandir import ScanDirIter, scandir, walk
from pyfakefs.helpers import (
IS_PYPY,
PERM_DEF,
PERM_EXE,
AnyString,
FakeStatResult,
get_gid,
get_uid,
is_byte_string,
is_called_from_skipped_module,
is_int_type,
is_byte_string,
is_root,
make_string_path,
IS_PYPY,
to_string,
matching_string,
AnyString,
to_bytes,
PERM_EXE,
PERM_DEF,
is_root,
get_uid,
get_gid,
to_string,
)

if TYPE_CHECKING:
Expand Down
Loading
Loading