Skip to content

Commit c879979

Browse files
committed
PathLike support 3.8
1 parent eaa0773 commit c879979

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

pathspec/pathspec.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
of files.
44
"""
55

6+
import sys
67
from collections.abc import (
78
Collection as CollectionType)
89
from itertools import (
@@ -30,6 +31,11 @@
3031
match_file,
3132
normalize_file)
3233

34+
if sys.version_info >= (3,9):
35+
StrPath = Union[str, PathLike[str]]
36+
else:
37+
StrPath = Union[str, PathLike]
38+
3339
Self = TypeVar("Self", bound="PathSpec")
3440
"""
3541
:class:`PathSpec` self type hint to support Python v<3.11 using PEP 673
@@ -164,7 +170,7 @@ def match_entries(
164170

165171
def match_file(
166172
self,
167-
file: Union[str, PathLike[str]],
173+
file: StrPath,
168174
separators: Optional[Collection[str]] = None,
169175
) -> bool:
170176
"""
@@ -184,9 +190,9 @@ def match_file(
184190

185191
def match_files(
186192
self,
187-
files: Iterable[Union[str, PathLike[str]]],
193+
files: Iterable[StrPath],
188194
separators: Optional[Collection[str]] = None,
189-
) -> Iterator[Union[str, PathLike[str]]]:
195+
) -> Iterator[StrPath]:
190196
"""
191197
Matches the files to this path-spec.
192198
@@ -213,7 +219,7 @@ def match_files(
213219

214220
def match_tree_entries(
215221
self,
216-
root: Union[str, PathLike[str]],
222+
root: StrPath,
217223
on_error: Optional[Callable] = None,
218224
follow_links: Optional[bool] = None,
219225
) -> Iterator[TreeEntry]:
@@ -240,7 +246,7 @@ def match_tree_entries(
240246

241247
def match_tree_files(
242248
self,
243-
root: Union[str, PathLike[str]],
249+
root: StrPath,
244250
on_error: Optional[Callable] = None,
245251
follow_links: Optional[bool] = None,
246252
) -> Iterator[str]:

pathspec/util.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pathlib
88
import posixpath
99
import stat
10+
import sys
1011
import warnings
1112
from collections.abc import (
1213
Collection as CollectionType,
@@ -30,6 +31,11 @@
3031
from .pattern import (
3132
Pattern)
3233

34+
if sys.version_info >= (3,9):
35+
StrPath = Union[str, PathLike[str]]
36+
else:
37+
StrPath = Union[str, PathLike]
38+
3339
NORMALIZE_PATH_SEPS = [
3440
__sep
3541
for __sep in [os.sep, os.altsep]
@@ -141,7 +147,7 @@ def _is_iterable(value: Any) -> bool:
141147

142148

143149
def iter_tree_entries(
144-
root: Union[str, PathLike[str]],
150+
root: StrPath,
145151
on_error: Optional[Callable] = None,
146152
follow_links: Optional[bool] = None,
147153
) -> Iterator['TreeEntry']:
@@ -257,7 +263,7 @@ def _iter_tree_entries_next(
257263

258264

259265
def iter_tree_files(
260-
root: Union[str, PathLike[str]],
266+
root: StrPath,
261267
on_error: Optional[Callable] = None,
262268
follow_links: Optional[bool] = None,
263269
) -> Iterator[str]:
@@ -365,7 +371,7 @@ def match_files(
365371

366372

367373
def normalize_file(
368-
file: Union[str, PathLike[str]],
374+
file: StrPath,
369375
separators: Optional[Collection[str]] = None,
370376
) -> str:
371377
"""
@@ -405,9 +411,9 @@ def normalize_file(
405411

406412

407413
def normalize_files(
408-
files: Iterable[Union[str, PathLike[str]]],
414+
files: Iterable[StrPath],
409415
separators: Optional[Collection[str]] = None,
410-
) -> Dict[str, List[Union[str, PathLike[str]]]]:
416+
) -> Dict[str, List[StrPath]]:
411417
"""
412418
DEPRECATED: This function is no longer used. Use the :func:`.normalize_file`
413419
function with a loop for better results.

0 commit comments

Comments
 (0)