Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unknown 'Self' #71

Merged
merged 1 commit into from Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 6 additions & 13 deletions pathspec/gitignore.py
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
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