Skip to content

Commit

Permalink
Replace black and flake 8 with ruff
Browse files Browse the repository at this point in the history
- adapt formatting where needed
  • Loading branch information
mrbean-bremen committed Feb 26, 2024
1 parent 5c44c64 commit a2f206b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 43 deletions.
19 changes: 6 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
23 changes: 15 additions & 8 deletions pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion pyfakefs/fake_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 11 additions & 11 deletions pyfakefs/fake_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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'.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions pyfakefs/fake_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
15 changes: 10 additions & 5 deletions pyfakefs/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions pyfakefs/patched_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a2f206b

Please sign in to comment.