Skip to content

Commit

Permalink
Fix partially unknown PathLike types
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Feb 18, 2023
1 parent a8ac206 commit eaa0773
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions pathspec/pathspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ def match_entries(

def match_file(
self,
file: Union[str, PathLike],
file: Union[str, PathLike[str]],
separators: Optional[Collection[str]] = None,
) -> bool:
"""
Matches the file to this path-spec.
*file* (:class:`str` or :class:`os.PathLike`) is the file path to be
*file* (:class:`str` or :class:`os.PathLike[str]`) is the file path to be
matched against :attr:`self.patterns <PathSpec.patterns>`.
*separators* (:class:`~collections.abc.Collection` of :class:`str`)
Expand All @@ -184,14 +184,14 @@ def match_file(

def match_files(
self,
files: Iterable[Union[str, PathLike]],
files: Iterable[Union[str, PathLike[str]]],
separators: Optional[Collection[str]] = None,
) -> Iterator[Union[str, PathLike]]:
) -> Iterator[Union[str, PathLike[str]]]:
"""
Matches the files to this path-spec.
*files* (:class:`~collections.abc.Iterable` of :class:`str` or
:class:`os.PathLike`) contains the file paths to be matched against
:class:`os.PathLike[str]`) contains the file paths to be matched against
:attr:`self.patterns <PathSpec.patterns>`.
*separators* (:class:`~collections.abc.Collection` of :class:`str`;
Expand All @@ -200,7 +200,7 @@ def match_files(
information.
Returns the matched files (:class:`~collections.abc.Iterator` of
:class:`str` or :class:`os.PathLike`).
:class:`str` or :class:`os.PathLike[str]`).
"""
if not _is_iterable(files):
raise TypeError(f"files:{files!r} is not an iterable.")
Expand All @@ -213,15 +213,15 @@ def match_files(

def match_tree_entries(
self,
root: Union[str, PathLike],
root: Union[str, PathLike[str]],
on_error: Optional[Callable] = None,
follow_links: Optional[bool] = None,
) -> Iterator[TreeEntry]:
"""
Walks the specified root path for all files and matches them to this
path-spec.
*root* (:class:`str` or :class:`os.PathLike`) is the root directory
*root* (:class:`str` or :class:`os.PathLike[str]`) is the root directory
to search.
*on_error* (:class:`~collections.abc.Callable` or :data:`None`)
Expand All @@ -240,15 +240,15 @@ def match_tree_entries(

def match_tree_files(
self,
root: Union[str, PathLike],
root: Union[str, PathLike[str]],
on_error: Optional[Callable] = None,
follow_links: Optional[bool] = None,
) -> Iterator[str]:
"""
Walks the specified root path for all files and matches them to this
path-spec.
*root* (:class:`str` or :class:`os.PathLike`) is the root directory
*root* (:class:`str` or :class:`os.PathLike[str]`) is the root directory
to search for files.
*on_error* (:class:`~collections.abc.Callable` or :data:`None`)
Expand Down
20 changes: 10 additions & 10 deletions pathspec/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ def _is_iterable(value: Any) -> bool:


def iter_tree_entries(
root: Union[str, PathLike],
root: Union[str, PathLike[str]],
on_error: Optional[Callable] = None,
follow_links: Optional[bool] = None,
) -> Iterator['TreeEntry']:
"""
Walks the specified directory for all files and directories.
*root* (:class:`str` or :class:`os.PathLike`) is the root directory to
*root* (:class:`str` or :class:`os.PathLike[str]`) is the root directory to
search.
*on_error* (:class:`~collections.abc.Callable` or :data:`None`)
Expand Down Expand Up @@ -257,14 +257,14 @@ def _iter_tree_entries_next(


def iter_tree_files(
root: Union[str, PathLike],
root: Union[str, PathLike[str]],
on_error: Optional[Callable] = None,
follow_links: Optional[bool] = None,
) -> Iterator[str]:
"""
Walks the specified directory for all files.
*root* (:class:`str` or :class:`os.PathLike`) is the root directory to
*root* (:class:`str` or :class:`os.PathLike[str]`) is the root directory to
search for files.
*on_error* (:class:`~collections.abc.Callable` or :data:`None`)
Expand Down Expand Up @@ -365,14 +365,14 @@ def match_files(


def normalize_file(
file: Union[str, PathLike],
file: Union[str, PathLike[str]],
separators: Optional[Collection[str]] = None,
) -> str:
"""
Normalizes the file path to use the POSIX path separator (i.e.,
:data:`'/'`), and make the paths relative (remove leading :data:`'/'`).
*file* (:class:`str` or :class:`os.PathLike`) is the file path.
*file* (:class:`str` or :class:`os.PathLike[str]`) is the file path.
*separators* (:class:`~collections.abc.Collection` of :class:`str`; or
:data:`None`) optionally contains the path separators to normalize.
Expand Down Expand Up @@ -405,25 +405,25 @@ def normalize_file(


def normalize_files(
files: Iterable[Union[str, PathLike]],
files: Iterable[Union[str, PathLike[str]]],
separators: Optional[Collection[str]] = None,
) -> Dict[str, List[Union[str, PathLike]]]:
) -> Dict[str, List[Union[str, PathLike[str]]]]:
"""
DEPRECATED: This function is no longer used. Use the :func:`.normalize_file`
function with a loop for better results.
Normalizes the file paths to use the POSIX path separator.
*files* (:class:`~collections.abc.Iterable` of :class:`str` or
:class:`os.PathLike`) contains the file paths to be normalized.
:class:`os.PathLike[str]`) contains the file paths to be normalized.
*separators* (:class:`~collections.abc.Collection` of :class:`str`; or
:data:`None`) optionally contains the path separators to normalize.
See :func:`normalize_file` for more information.
Returns a :class:`dict` mapping each normalized file path (:class:`str`)
to the original file paths (:class:`list` of :class:`str` or
:class:`os.PathLike`).
:class:`os.PathLike[str]`).
"""
warnings.warn((
"util.normalize_files() is deprecated. Use util.normalize_file() "
Expand Down

0 comments on commit eaa0773

Please sign in to comment.