diff --git a/pathspec/pathspec.py b/pathspec/pathspec.py index bb88cbf..7c99b1c 100644 --- a/pathspec/pathspec.py +++ b/pathspec/pathspec.py @@ -98,13 +98,13 @@ def __init__( contains the compiled patterns. """ - def __add__(self: Self, other: PathSpec) -> Self: + def __add__(self: Self, other: object) -> Self: """ Combines the :attr:`self.patterns <.PathSpec.patterns>` patterns from two :class:`PathSpec` instances. """ if isinstance(other, PathSpec): - return self.__class__(self.patterns + other.patterns, backend=self._backend_name) + return self.__class__([*self.patterns, *other.patterns], backend=self._backend_name) else: return NotImplemented @@ -119,7 +119,7 @@ def __eq__(self, other: object) -> bool: else: return NotImplemented - def __iadd__(self: Self, other: PathSpec) -> Self: + def __iadd__(self: Self, other: object) -> Self: """ Adds the :attr:`self.patterns <.PathSpec.patterns>` from *other* (:class:`PathSpec`) to this instance. diff --git a/pathspec/pattern.py b/pathspec/pattern.py index a4b8a2c..351af78 100644 --- a/pathspec/pattern.py +++ b/pathspec/pattern.py @@ -168,7 +168,7 @@ def __copy__(self: RegexPatternSelf) -> RegexPatternSelf: other.pattern = self.pattern return other - def __eq__(self, other: RegexPattern) -> bool: + def __eq__(self, other: object) -> bool: """ Tests the equality of this regex pattern with *other* (:class:`RegexPattern`) by comparing their :attr:`~Pattern.include` and :attr:`~RegexPattern.regex` diff --git a/pathspec/util.py b/pathspec/util.py index ea2dbee..9a3f2c1 100644 --- a/pathspec/util.py +++ b/pathspec/util.py @@ -146,10 +146,11 @@ def detailed_match_files( # Add files and record pattern. for result_file in result_files: if result_file in return_files: + # We know here that .patterns is a list, becasue we made it here if all_matches: - return_files[result_file].patterns.append(pattern) + return_files[result_file].patterns.append(pattern) # type: ignore[attr-defined] else: - return_files[result_file].patterns[0] = pattern + return_files[result_file].patterns[0] = pattern # type: ignore[index] else: return_files[result_file] = MatchDetail([pattern])