From 7865e9fa82c26b2603e3928cee617317b1aebe70 Mon Sep 17 00:00:00 2001 From: cpburnz <2126043+cpburnz@users.noreply.github.com> Date: Sat, 3 Dec 2022 09:33:52 -0500 Subject: [PATCH] Fix #70 incompatibility --- pathspec/gitignore.py | 10 +++++++--- pathspec/pathspec.py | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pathspec/gitignore.py b/pathspec/gitignore.py index 3e0e0dc..0c3481c 100644 --- a/pathspec/gitignore.py +++ b/pathspec/gitignore.py @@ -8,7 +8,7 @@ Callable, Collection, Iterable, - TYPE_CHECKING, + Type, TypeVar, Union) @@ -23,7 +23,11 @@ from .util import ( _is_iterable) -Self = TypeVar("Self") +Self = TypeVar("Self", bound="GitIgnoreSpec") +""" +:class:`GitIgnoreSpec` self type hint to support Python v<3.11 using PEP +673 recommendation. +""" class GitIgnoreSpec(PathSpec): @@ -47,7 +51,7 @@ def __eq__(self, other: object) -> bool: @classmethod def from_lines( - cls: type[Self], + cls: Type[Self], lines: Iterable[AnyStr], pattern_factory: Union[str, Callable[[AnyStr], Pattern], None] = None, ) -> Self: diff --git a/pathspec/pathspec.py b/pathspec/pathspec.py index f16f45b..bd46f8e 100644 --- a/pathspec/pathspec.py +++ b/pathspec/pathspec.py @@ -16,7 +16,7 @@ Iterable, Iterator, Optional, - TYPE_CHECKING, + Type, TypeVar, Union) @@ -30,7 +30,11 @@ match_file, normalize_file) -Self = TypeVar("Self") +Self = TypeVar("Self", bound="PathSpec") +""" +:class:`PathSpec` self type hint to support Python v<3.11 using PEP 673 +recommendation. +""" class PathSpec(object): @@ -94,7 +98,7 @@ def __iadd__(self: Self, other: "PathSpec") -> Self: @classmethod def from_lines( - cls: type[Self], + cls: Type[Self], pattern_factory: Union[str, Callable[[AnyStr], Pattern]], lines: Iterable[AnyStr], ) -> Self: