Skip to content

Commit bf39aa3

Browse files
committed
Replace black and flake 8 with ruff
- adapt formatting where needed
1 parent 5c44c64 commit bf39aa3

7 files changed

+52
-43
lines changed

.pre-commit-config.yaml

+6-13
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ default_language_version:
22
python: "3.10"
33

44
repos:
5+
- repo: https://github.com/astral-sh/ruff-pre-commit
6+
rev: "v0.2.0"
7+
hooks:
8+
- id: ruff
9+
args: ["--fix"]
10+
- id: ruff-format
511
- repo: https://github.com/codespell-project/codespell
612
rev: v2.2.6
713
hooks:
814
- id: codespell
915
args:
1016
- --ignore-words-list=wronly,afile
11-
- repo: https://github.com/psf/black
12-
rev: 24.2.0
13-
hooks:
14-
- id: black
15-
args: [ --safe, --quiet ]
1617
- repo: https://github.com/asottile/blacken-docs
1718
rev: 1.16.0
1819
hooks:
@@ -36,14 +37,6 @@ repos:
3637
args: ["--in-place", "--remove-unused-variables", "--remove-all-unused-imports"]
3738
language: python
3839
files: \.py$
39-
- repo: https://github.com/PyCQA/flake8
40-
rev: 7.0.0
41-
hooks:
42-
- id: flake8
43-
language_version: python3
44-
additional_dependencies:
45-
- flake8-bugbear
46-
args: ["--extend-ignore=E203", "--max-line-length=88"]
4740
- repo: https://github.com/pre-commit/mirrors-mypy
4841
rev: v1.8.0
4942
hooks:

pyfakefs/fake_filesystem.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,9 @@ def os(self) -> OSType:
321321
return (
322322
OSType.WINDOWS
323323
if self.is_windows_fs
324-
else OSType.MACOS if self.is_macos else OSType.LINUX
324+
else OSType.MACOS
325+
if self.is_macos
326+
else OSType.LINUX
325327
)
326328

327329
@os.setter
@@ -928,9 +930,9 @@ def normpath(self, path: AnyStr) -> AnyStr:
928930
path_components: List[AnyStr] = path_str.split(
929931
sep
930932
) # pytype: disable=invalid-annotation
931-
collapsed_path_components: List[AnyStr] = (
932-
[]
933-
) # pytype: disable=invalid-annotation
933+
collapsed_path_components: List[
934+
AnyStr
935+
] = [] # pytype: disable=invalid-annotation
934936
dot = matching_string(path_str, ".")
935937
dotdot = matching_string(path_str, "..")
936938
for component in path_components:
@@ -1218,10 +1220,12 @@ def joinpaths(self, *paths: AnyStr) -> AnyStr:
12181220
return matching_string(file_paths[0], "").join(joined_path_segments)
12191221

12201222
@overload
1221-
def _path_components(self, path: str) -> List[str]: ...
1223+
def _path_components(self, path: str) -> List[str]:
1224+
...
12221225

12231226
@overload
1224-
def _path_components(self, path: bytes) -> List[bytes]: ...
1227+
def _path_components(self, path: bytes) -> List[bytes]:
1228+
...
12251229

12261230
def _path_components(self, path: AnyStr) -> List[AnyStr]:
12271231
"""Breaks the path into a list of component names.
@@ -1884,7 +1888,9 @@ def _handle_broken_link_with_trailing_sep(self, path: AnyStr) -> None:
18841888
error = (
18851889
errno.ENOENT
18861890
if self.is_macos
1887-
else errno.EINVAL if self.is_windows_fs else errno.ENOTDIR
1891+
else errno.EINVAL
1892+
if self.is_windows_fs
1893+
else errno.ENOTDIR
18881894
)
18891895
self.raise_os_error(error, path)
18901896

@@ -2413,7 +2419,8 @@ def create_file_internally(
24132419
if not create_missing_dirs:
24142420
self.raise_os_error(errno.ENOENT, parent_directory)
24152421
parent_directory = matching_string(
2416-
path, self.create_dir(parent_directory).path # type: ignore
2422+
path,
2423+
self.create_dir(parent_directory).path, # type: ignore
24172424
)
24182425
else:
24192426
parent_directory = self._original_path(parent_directory)

pyfakefs/fake_open.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ def _init_file_object(
292292
error = (
293293
errno.EINVAL
294294
if self.filesystem.is_windows_fs
295-
else errno.ENOENT if self.filesystem.is_macos else errno.EISDIR
295+
else errno.ENOENT
296+
if self.filesystem.is_macos
297+
else errno.EISDIR
296298
)
297299
self.filesystem.raise_os_error(error, file_path)
298300
file_object = self.filesystem.create_file_internally(

pyfakefs/fake_os.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def open(
219219
flags: int,
220220
mode: Optional[int] = None,
221221
*,
222-
dir_fd: Optional[int] = None
222+
dir_fd: Optional[int] = None,
223223
) -> int:
224224
"""Return the file descriptor for a FakeFile.
225225
@@ -538,7 +538,7 @@ def setxattr(
538538
value: bytes,
539539
flags: int = 0,
540540
*,
541-
follow_symlinks: bool = True
541+
follow_symlinks: bool = True,
542542
) -> None:
543543
"""Sets the value of the given extended filesystem attribute for
544544
`path`.
@@ -634,7 +634,7 @@ def stat(
634634
path: AnyStr,
635635
*,
636636
dir_fd: Optional[int] = None,
637-
follow_symlinks: bool = True
637+
follow_symlinks: bool = True,
638638
) -> FakeStatResult:
639639
"""Return the os.stat-like tuple for the FakeFile object of entry_path.
640640
@@ -712,7 +712,7 @@ def rename(
712712
dst: AnyStr,
713713
*,
714714
src_dir_fd: Optional[int] = None,
715-
dst_dir_fd: Optional[int] = None
715+
dst_dir_fd: Optional[int] = None,
716716
) -> None:
717717
"""Rename a FakeFile object at old_file_path to new_file_path,
718718
preserving all properties.
@@ -774,7 +774,7 @@ def replace(
774774
dst: AnyStr,
775775
*,
776776
src_dir_fd: Optional[int] = None,
777-
dst_dir_fd: Optional[int] = None
777+
dst_dir_fd: Optional[int] = None,
778778
) -> None:
779779
"""Renames a FakeFile object at old_file_path to new_file_path,
780780
preserving all properties.
@@ -957,7 +957,7 @@ def access(
957957
*,
958958
dir_fd: Optional[int] = None,
959959
effective_ids: bool = False,
960-
follow_symlinks: bool = True
960+
follow_symlinks: bool = True,
961961
) -> bool:
962962
"""Check if a file exists and has the specified permissions.
963963
@@ -995,7 +995,7 @@ def chmod(
995995
mode: int,
996996
*,
997997
dir_fd: Optional[int] = None,
998-
follow_symlinks: bool = True
998+
follow_symlinks: bool = True,
999999
) -> None:
10001000
"""Change the permissions of a file as encoded in integer mode.
10011001
@@ -1067,7 +1067,7 @@ def chown(
10671067
gid: int,
10681068
*,
10691069
dir_fd: Optional[int] = None,
1070-
follow_symlinks: bool = True
1070+
follow_symlinks: bool = True,
10711071
) -> None:
10721072
"""Set ownership of a faked file.
10731073
@@ -1102,7 +1102,7 @@ def mknod(
11021102
mode: Optional[int] = None,
11031103
device: int = 0,
11041104
*,
1105-
dir_fd: Optional[int] = None
1105+
dir_fd: Optional[int] = None,
11061106
) -> None:
11071107
"""Create a filesystem node named 'filename'.
11081108
@@ -1153,7 +1153,7 @@ def symlink(
11531153
dst: AnyStr,
11541154
target_is_directory: bool = False,
11551155
*,
1156-
dir_fd: Optional[int] = None
1156+
dir_fd: Optional[int] = None,
11571157
) -> None:
11581158
"""Creates the specified symlink, pointed at the specified link target.
11591159
@@ -1176,7 +1176,7 @@ def link(
11761176
dst: AnyStr,
11771177
*,
11781178
src_dir_fd: Optional[int] = None,
1179-
dst_dir_fd: Optional[int] = None
1179+
dst_dir_fd: Optional[int] = None,
11801180
) -> None:
11811181
"""Create a hard link at new_path, pointing at old_path.
11821182

pyfakefs/fake_path.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,14 @@ def samefile(self, path1: AnyStr, path2: AnyStr) -> bool:
368368
@overload
369369
def _join_real_path(
370370
self, path: str, rest: str, seen: Dict[str, Optional[str]]
371-
) -> Tuple[str, bool]: ...
371+
) -> Tuple[str, bool]:
372+
...
372373

373374
@overload
374375
def _join_real_path(
375376
self, path: bytes, rest: bytes, seen: Dict[bytes, Optional[bytes]]
376-
) -> Tuple[bytes, bool]: ...
377+
) -> Tuple[bytes, bool]:
378+
...
377379

378380
def _join_real_path(
379381
self, path: AnyStr, rest: AnyStr, seen: Dict[AnyStr, Optional[AnyStr]]

pyfakefs/helpers.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,13 @@ def is_unicode_string(val: Any) -> bool:
110110

111111

112112
@overload
113-
def make_string_path(dir_name: AnyStr) -> AnyStr: ...
113+
def make_string_path(dir_name: AnyStr) -> AnyStr:
114+
...
114115

115116

116117
@overload
117-
def make_string_path(dir_name: os.PathLike) -> str: ...
118+
def make_string_path(dir_name: os.PathLike) -> str:
119+
...
118120

119121

120122
def make_string_path(dir_name: AnyPath) -> AnyStr: # type: ignore[type-var]
@@ -156,15 +158,18 @@ def now():
156158

157159

158160
@overload
159-
def matching_string(matched: bytes, string: AnyStr) -> bytes: ...
161+
def matching_string(matched: bytes, string: AnyStr) -> bytes:
162+
...
160163

161164

162165
@overload
163-
def matching_string(matched: str, string: AnyStr) -> str: ...
166+
def matching_string(matched: str, string: AnyStr) -> str:
167+
...
164168

165169

166170
@overload
167-
def matching_string(matched: AnyStr, string: None) -> None: ...
171+
def matching_string(matched: AnyStr, string: None) -> None:
172+
...
168173

169174

170175
def matching_string( # type: ignore[misc]

pyfakefs/patched_packages.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ def reload_handler(name):
8080
def get_cleanup_handlers():
8181
handlers = {}
8282
if pd is not None:
83-
handlers["pandas.core.arrays.arrow.extension_types"] = (
84-
handle_extension_type_cleanup
85-
)
83+
handlers[
84+
"pandas.core.arrays.arrow.extension_types"
85+
] = handle_extension_type_cleanup
8686
if django is not None:
8787
for module_name in django_view_modules():
8888
handlers[module_name] = lambda name=module_name: reload_handler(name)

0 commit comments

Comments
 (0)