Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pathspec/pathspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ def __init__(
contains the compiled patterns.
"""

def __add__(self: Self, other: PathSpec) -> Self:
def __add__(self: Self, other: object) -> Self:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's best to keep other: PathSpec.

If it's changed to other: object, then PyCharm will no longer flag:

spec2 = spec + 123  # Expected type 'PathSpec', got 'int' instead 

Does mypy complain about other not being hinted as object?

"""
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

Expand All @@ -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:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's best to keep other: PathSpec.

Unfortunately PyCharm does not flag this as an error even though type-wise it's wrong:

spec += 123

Does mypy complain about other not being hinted as object?

"""
Adds the :attr:`self.patterns <.PathSpec.patterns>` from *other*
(:class:`PathSpec`) to this instance.
Expand Down
2 changes: 1 addition & 1 deletion pathspec/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
5 changes: 3 additions & 2 deletions pathspec/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down