Skip to content

Commit

Permalink
PathLike support 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Feb 18, 2023
1 parent eaa0773 commit c879979
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
16 changes: 11 additions & 5 deletions pathspec/pathspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
of files.
"""

import sys
from collections.abc import (
Collection as CollectionType)
from itertools import (
Expand Down Expand Up @@ -30,6 +31,11 @@
match_file,
normalize_file)

if sys.version_info >= (3,9):
StrPath = Union[str, PathLike[str]]
else:
StrPath = Union[str, PathLike]

Self = TypeVar("Self", bound="PathSpec")
"""
:class:`PathSpec` self type hint to support Python v<3.11 using PEP 673
Expand Down Expand Up @@ -164,7 +170,7 @@ def match_entries(

def match_file(
self,
file: Union[str, PathLike[str]],
file: StrPath,
separators: Optional[Collection[str]] = None,
) -> bool:
"""
Expand All @@ -184,9 +190,9 @@ def match_file(

def match_files(
self,
files: Iterable[Union[str, PathLike[str]]],
files: Iterable[StrPath],
separators: Optional[Collection[str]] = None,
) -> Iterator[Union[str, PathLike[str]]]:
) -> Iterator[StrPath]:
"""
Matches the files to this path-spec.
Expand All @@ -213,7 +219,7 @@ def match_files(

def match_tree_entries(
self,
root: Union[str, PathLike[str]],
root: StrPath,
on_error: Optional[Callable] = None,
follow_links: Optional[bool] = None,
) -> Iterator[TreeEntry]:
Expand All @@ -240,7 +246,7 @@ def match_tree_entries(

def match_tree_files(
self,
root: Union[str, PathLike[str]],
root: StrPath,
on_error: Optional[Callable] = None,
follow_links: Optional[bool] = None,
) -> Iterator[str]:
Expand Down
16 changes: 11 additions & 5 deletions pathspec/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pathlib
import posixpath
import stat
import sys
import warnings
from collections.abc import (
Collection as CollectionType,
Expand All @@ -30,6 +31,11 @@
from .pattern import (
Pattern)

if sys.version_info >= (3,9):
StrPath = Union[str, PathLike[str]]
else:
StrPath = Union[str, PathLike]

NORMALIZE_PATH_SEPS = [
__sep
for __sep in [os.sep, os.altsep]
Expand Down Expand Up @@ -141,7 +147,7 @@ def _is_iterable(value: Any) -> bool:


def iter_tree_entries(
root: Union[str, PathLike[str]],
root: StrPath,
on_error: Optional[Callable] = None,
follow_links: Optional[bool] = None,
) -> Iterator['TreeEntry']:
Expand Down Expand Up @@ -257,7 +263,7 @@ def _iter_tree_entries_next(


def iter_tree_files(
root: Union[str, PathLike[str]],
root: StrPath,
on_error: Optional[Callable] = None,
follow_links: Optional[bool] = None,
) -> Iterator[str]:
Expand Down Expand Up @@ -365,7 +371,7 @@ def match_files(


def normalize_file(
file: Union[str, PathLike[str]],
file: StrPath,
separators: Optional[Collection[str]] = None,
) -> str:
"""
Expand Down Expand Up @@ -405,9 +411,9 @@ def normalize_file(


def normalize_files(
files: Iterable[Union[str, PathLike[str]]],
files: Iterable[StrPath],
separators: Optional[Collection[str]] = None,
) -> Dict[str, List[Union[str, PathLike[str]]]]:
) -> Dict[str, List[StrPath]]:
"""
DEPRECATED: This function is no longer used. Use the :func:`.normalize_file`
function with a loop for better results.
Expand Down

0 comments on commit c879979

Please sign in to comment.