Skip to content

Commit

Permalink
Merge pull request #71 from Avasam/unknown-'Self'-type
Browse files Browse the repository at this point in the history
Fix unknown 'Self'
  • Loading branch information
cpburnz committed Dec 3, 2022
2 parents c986041 + 0a0c472 commit 9adbcd2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
19 changes: 6 additions & 13 deletions pathspec/gitignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Collection,
Iterable,
TYPE_CHECKING,
TypeVar,
Union)

from .pathspec import (
Expand All @@ -22,14 +23,16 @@
from .util import (
_is_iterable)

Self = TypeVar("Self")


class GitIgnoreSpec(PathSpec):
"""
The :class:`GitIgnoreSpec` class extends :class:`PathSpec` to
replicate *.gitignore* behavior.
"""

def __eq__(self, other: 'Self') -> bool:
def __eq__(self, other: object) -> bool:
"""
Tests the equality of this gitignore-spec with *other*
(:class:`GitIgnoreSpec`) by comparing their :attr:`~PathSpec.patterns`
Expand All @@ -44,10 +47,10 @@ def __eq__(self, other: 'Self') -> bool:

@classmethod
def from_lines(
cls,
cls: type[Self],
lines: Iterable[AnyStr],
pattern_factory: Union[str, Callable[[AnyStr], Pattern], None] = None,
) -> 'Self':
) -> Self:
"""
Compiles the pattern lines.
Expand Down Expand Up @@ -126,13 +129,3 @@ def _match_file(
out_priority = priority

return out_matched


if TYPE_CHECKING:
try:
from typing import Self
except ImportError:
try:
from typing_extensions import Self
except ImportError:
Self = GitIgnoreSpec
23 changes: 8 additions & 15 deletions pathspec/pathspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Iterator,
Optional,
TYPE_CHECKING,
TypeVar,
Union)

from . import util
Expand All @@ -29,6 +30,8 @@
match_file,
normalize_file)

Self = TypeVar("Self")


class PathSpec(object):
"""
Expand All @@ -50,7 +53,7 @@ def __init__(self, patterns: Iterable[Pattern]) -> None:
contains the compiled patterns.
"""

def __eq__(self, other: 'Self') -> bool:
def __eq__(self, other: object) -> bool:
"""
Tests the equality of this path-spec with *other* (:class:`PathSpec`)
by comparing their :attr:`~PathSpec.patterns` attributes.
Expand All @@ -68,7 +71,7 @@ def __len__(self) -> int:
"""
return len(self.patterns)

def __add__(self, other: 'Self') -> 'Self':
def __add__(self: Self, other: "PathSpec") -> Self:
"""
Combines the :attr:`Pathspec.patterns` patterns from two
:class:`PathSpec` instances.
Expand All @@ -78,7 +81,7 @@ def __add__(self, other: 'Self') -> 'Self':
else:
return NotImplemented

def __iadd__(self, other: 'Self') -> 'Self':
def __iadd__(self: Self, other: "PathSpec") -> Self:
"""
Adds the :attr:`Pathspec.patterns` patterns from one :class:`PathSpec`
instance to this instance.
Expand All @@ -91,10 +94,10 @@ def __iadd__(self, other: 'Self') -> 'Self':

@classmethod
def from_lines(
cls,
cls: type[Self],
pattern_factory: Union[str, Callable[[AnyStr], Pattern]],
lines: Iterable[AnyStr],
) -> 'Self':
) -> Self:
"""
Compiles the pattern lines.
Expand Down Expand Up @@ -261,13 +264,3 @@ def match_tree_files(
# Alias `match_tree_files()` as `match_tree()` for backward
# compatibility before v0.3.2.
match_tree = match_tree_files


if TYPE_CHECKING:
try:
from typing import Self
except ImportError:
try:
from typing_extensions import Self
except ImportError:
Self = PathSpec

0 comments on commit 9adbcd2

Please sign in to comment.