diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 576c6249..60c9f6e1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,17 +2,18 @@ default_language_version: python: "3.10" repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: "v0.2.0" + hooks: + - id: ruff + args: ["--fix"] + - id: ruff-format - repo: https://github.com/codespell-project/codespell rev: v2.2.6 hooks: - id: codespell args: - --ignore-words-list=wronly,afile - - repo: https://github.com/psf/black - rev: 24.2.0 - hooks: - - id: black - args: [ --safe, --quiet ] - repo: https://github.com/asottile/blacken-docs rev: 1.16.0 hooks: @@ -36,14 +37,6 @@ repos: args: ["--in-place", "--remove-unused-variables", "--remove-all-unused-imports"] language: python files: \.py$ - - repo: https://github.com/PyCQA/flake8 - rev: 7.0.0 - hooks: - - id: flake8 - language_version: python3 - additional_dependencies: - - flake8-bugbear - args: ["--extend-ignore=E203", "--max-line-length=88"] - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.8.0 hooks: diff --git a/pyfakefs/fake_filesystem.py b/pyfakefs/fake_filesystem.py index 46a028c5..74f1a082 100644 --- a/pyfakefs/fake_filesystem.py +++ b/pyfakefs/fake_filesystem.py @@ -321,7 +321,9 @@ def os(self) -> OSType: return ( OSType.WINDOWS if self.is_windows_fs - else OSType.MACOS if self.is_macos else OSType.LINUX + else OSType.MACOS + if self.is_macos + else OSType.LINUX ) @os.setter @@ -928,9 +930,9 @@ def normpath(self, path: AnyStr) -> AnyStr: path_components: List[AnyStr] = path_str.split( sep ) # pytype: disable=invalid-annotation - collapsed_path_components: List[AnyStr] = ( - [] - ) # pytype: disable=invalid-annotation + collapsed_path_components: List[ + AnyStr + ] = [] # pytype: disable=invalid-annotation dot = matching_string(path_str, ".") dotdot = matching_string(path_str, "..") for component in path_components: @@ -1218,10 +1220,12 @@ def joinpaths(self, *paths: AnyStr) -> AnyStr: return matching_string(file_paths[0], "").join(joined_path_segments) @overload - def _path_components(self, path: str) -> List[str]: ... + def _path_components(self, path: str) -> List[str]: + ... @overload - def _path_components(self, path: bytes) -> List[bytes]: ... + def _path_components(self, path: bytes) -> List[bytes]: + ... def _path_components(self, path: AnyStr) -> List[AnyStr]: """Breaks the path into a list of component names. @@ -1884,7 +1888,9 @@ def _handle_broken_link_with_trailing_sep(self, path: AnyStr) -> None: error = ( errno.ENOENT if self.is_macos - else errno.EINVAL if self.is_windows_fs else errno.ENOTDIR + else errno.EINVAL + if self.is_windows_fs + else errno.ENOTDIR ) self.raise_os_error(error, path) @@ -2413,7 +2419,8 @@ def create_file_internally( if not create_missing_dirs: self.raise_os_error(errno.ENOENT, parent_directory) parent_directory = matching_string( - path, self.create_dir(parent_directory).path # type: ignore + path, + self.create_dir(parent_directory).path, # type: ignore ) else: parent_directory = self._original_path(parent_directory) diff --git a/pyfakefs/fake_open.py b/pyfakefs/fake_open.py index 1e07252c..e6024296 100644 --- a/pyfakefs/fake_open.py +++ b/pyfakefs/fake_open.py @@ -292,7 +292,9 @@ def _init_file_object( error = ( errno.EINVAL if self.filesystem.is_windows_fs - else errno.ENOENT if self.filesystem.is_macos else errno.EISDIR + else errno.ENOENT + if self.filesystem.is_macos + else errno.EISDIR ) self.filesystem.raise_os_error(error, file_path) file_object = self.filesystem.create_file_internally( diff --git a/pyfakefs/fake_os.py b/pyfakefs/fake_os.py index 152d5a24..660ba6c5 100644 --- a/pyfakefs/fake_os.py +++ b/pyfakefs/fake_os.py @@ -219,7 +219,7 @@ def open( flags: int, mode: Optional[int] = None, *, - dir_fd: Optional[int] = None + dir_fd: Optional[int] = None, ) -> int: """Return the file descriptor for a FakeFile. @@ -538,7 +538,7 @@ def setxattr( value: bytes, flags: int = 0, *, - follow_symlinks: bool = True + follow_symlinks: bool = True, ) -> None: """Sets the value of the given extended filesystem attribute for `path`. @@ -634,7 +634,7 @@ def stat( path: AnyStr, *, dir_fd: Optional[int] = None, - follow_symlinks: bool = True + follow_symlinks: bool = True, ) -> FakeStatResult: """Return the os.stat-like tuple for the FakeFile object of entry_path. @@ -712,7 +712,7 @@ def rename( dst: AnyStr, *, src_dir_fd: Optional[int] = None, - dst_dir_fd: Optional[int] = None + dst_dir_fd: Optional[int] = None, ) -> None: """Rename a FakeFile object at old_file_path to new_file_path, preserving all properties. @@ -774,7 +774,7 @@ def replace( dst: AnyStr, *, src_dir_fd: Optional[int] = None, - dst_dir_fd: Optional[int] = None + dst_dir_fd: Optional[int] = None, ) -> None: """Renames a FakeFile object at old_file_path to new_file_path, preserving all properties. @@ -957,7 +957,7 @@ def access( *, dir_fd: Optional[int] = None, effective_ids: bool = False, - follow_symlinks: bool = True + follow_symlinks: bool = True, ) -> bool: """Check if a file exists and has the specified permissions. @@ -995,7 +995,7 @@ def chmod( mode: int, *, dir_fd: Optional[int] = None, - follow_symlinks: bool = True + follow_symlinks: bool = True, ) -> None: """Change the permissions of a file as encoded in integer mode. @@ -1067,7 +1067,7 @@ def chown( gid: int, *, dir_fd: Optional[int] = None, - follow_symlinks: bool = True + follow_symlinks: bool = True, ) -> None: """Set ownership of a faked file. @@ -1102,7 +1102,7 @@ def mknod( mode: Optional[int] = None, device: int = 0, *, - dir_fd: Optional[int] = None + dir_fd: Optional[int] = None, ) -> None: """Create a filesystem node named 'filename'. @@ -1153,7 +1153,7 @@ def symlink( dst: AnyStr, target_is_directory: bool = False, *, - dir_fd: Optional[int] = None + dir_fd: Optional[int] = None, ) -> None: """Creates the specified symlink, pointed at the specified link target. @@ -1176,7 +1176,7 @@ def link( dst: AnyStr, *, src_dir_fd: Optional[int] = None, - dst_dir_fd: Optional[int] = None + dst_dir_fd: Optional[int] = None, ) -> None: """Create a hard link at new_path, pointing at old_path. diff --git a/pyfakefs/fake_path.py b/pyfakefs/fake_path.py index 63e4773e..e6b261bf 100644 --- a/pyfakefs/fake_path.py +++ b/pyfakefs/fake_path.py @@ -368,12 +368,14 @@ def samefile(self, path1: AnyStr, path2: AnyStr) -> bool: @overload def _join_real_path( self, path: str, rest: str, seen: Dict[str, Optional[str]] - ) -> Tuple[str, bool]: ... + ) -> Tuple[str, bool]: + ... @overload def _join_real_path( self, path: bytes, rest: bytes, seen: Dict[bytes, Optional[bytes]] - ) -> Tuple[bytes, bool]: ... + ) -> Tuple[bytes, bool]: + ... def _join_real_path( self, path: AnyStr, rest: AnyStr, seen: Dict[AnyStr, Optional[AnyStr]] diff --git a/pyfakefs/helpers.py b/pyfakefs/helpers.py index 9ef434c7..416be19b 100644 --- a/pyfakefs/helpers.py +++ b/pyfakefs/helpers.py @@ -110,11 +110,13 @@ def is_unicode_string(val: Any) -> bool: @overload -def make_string_path(dir_name: AnyStr) -> AnyStr: ... +def make_string_path(dir_name: AnyStr) -> AnyStr: + ... @overload -def make_string_path(dir_name: os.PathLike) -> str: ... +def make_string_path(dir_name: os.PathLike) -> str: + ... def make_string_path(dir_name: AnyPath) -> AnyStr: # type: ignore[type-var] @@ -156,15 +158,18 @@ def now(): @overload -def matching_string(matched: bytes, string: AnyStr) -> bytes: ... +def matching_string(matched: bytes, string: AnyStr) -> bytes: + ... @overload -def matching_string(matched: str, string: AnyStr) -> str: ... +def matching_string(matched: str, string: AnyStr) -> str: + ... @overload -def matching_string(matched: AnyStr, string: None) -> None: ... +def matching_string(matched: AnyStr, string: None) -> None: + ... def matching_string( # type: ignore[misc] diff --git a/pyfakefs/patched_packages.py b/pyfakefs/patched_packages.py index 9f343e0c..6ff927fc 100644 --- a/pyfakefs/patched_packages.py +++ b/pyfakefs/patched_packages.py @@ -80,9 +80,9 @@ def reload_handler(name): def get_cleanup_handlers(): handlers = {} if pd is not None: - handlers["pandas.core.arrays.arrow.extension_types"] = ( - handle_extension_type_cleanup - ) + handlers[ + "pandas.core.arrays.arrow.extension_types" + ] = handle_extension_type_cleanup if django is not None: for module_name in django_view_modules(): handlers[module_name] = lambda name=module_name: reload_handler(name)