Skip to content

Commit

Permalink
Refactor to remove type parameter from MatcherSpecInvalidError constr…
Browse files Browse the repository at this point in the history
…uctor
  • Loading branch information
c0llab0rat0r authored and ntninja committed May 6, 2021
1 parent 37a488a commit 895df8b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
6 changes: 3 additions & 3 deletions ipfshttpclient/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ def __init__(self, encoder_name: str, original: Exception) -> None:
# filescanner.py #
##################

class MatcherSpecInvalidError(TypeError):
class MatcherSpecInvalidError(Error, TypeError):
"""
An attempt was made to build a matcher using matcher_from_spec, but an invalid
specification was provided.
"""

def __init__(self, matcher_class: type, invalid_spec: ty.Any) -> None:
def __init__(self, invalid_spec: ty.Any) -> None:
super().__init__(
f"Don't know how to create a {matcher_class.__name__} from spec {invalid_spec!r}"
f"Don't know how to create a Matcher from spec {invalid_spec!r}"
)


Expand Down
2 changes: 1 addition & 1 deletion ipfshttpclient/filescanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def _recursive_matcher_from_spec(spec: match_spec_t[AnyStr], *,
else: # Actual list of matchers (plural)
return MetaMatcher(matchers)
else:
raise MatcherSpecInvalidError(Matcher, spec)
raise MatcherSpecInvalidError(spec)


class walk(ty.Generator[FSNodeEntry[AnyStr], ty.Any, None], ty.Generic[AnyStr]):
Expand Down
18 changes: 18 additions & 0 deletions test/unit/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

from ipfshttpclient.exceptions import MatcherSpecInvalidError, Error
from ipfshttpclient.filescanner import Matcher


def test_matcher_spec_invalid_error_message():
ex = MatcherSpecInvalidError('junk')
assert ex.args[0] == f"Don't know how to create a {Matcher.__name__} from spec 'junk'"


def test_matcher_spec_invalid_error_multiple_inheritance():
ex = MatcherSpecInvalidError('wrong')

# Base class of all exceptions in this library
assert isinstance(ex, Error)

# Base class of type errors
assert isinstance(ex, TypeError)

0 comments on commit 895df8b

Please sign in to comment.