Skip to content

Commit 895df8b

Browse files
c0llab0rat0rntninja
authored andcommitted
Refactor to remove type parameter from MatcherSpecInvalidError constructor
1 parent 37a488a commit 895df8b

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

ipfshttpclient/exceptions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ def __init__(self, encoder_name: str, original: Exception) -> None:
115115
# filescanner.py #
116116
##################
117117

118-
class MatcherSpecInvalidError(TypeError):
118+
class MatcherSpecInvalidError(Error, TypeError):
119119
"""
120120
An attempt was made to build a matcher using matcher_from_spec, but an invalid
121121
specification was provided.
122122
"""
123123

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

129129

ipfshttpclient/filescanner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ def _recursive_matcher_from_spec(spec: match_spec_t[AnyStr], *,
497497
else: # Actual list of matchers (plural)
498498
return MetaMatcher(matchers)
499499
else:
500-
raise MatcherSpecInvalidError(Matcher, spec)
500+
raise MatcherSpecInvalidError(spec)
501501

502502

503503
class walk(ty.Generator[FSNodeEntry[AnyStr], ty.Any, None], ty.Generic[AnyStr]):

test/unit/test_exceptions.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
from ipfshttpclient.exceptions import MatcherSpecInvalidError, Error
3+
from ipfshttpclient.filescanner import Matcher
4+
5+
6+
def test_matcher_spec_invalid_error_message():
7+
ex = MatcherSpecInvalidError('junk')
8+
assert ex.args[0] == f"Don't know how to create a {Matcher.__name__} from spec 'junk'"
9+
10+
11+
def test_matcher_spec_invalid_error_multiple_inheritance():
12+
ex = MatcherSpecInvalidError('wrong')
13+
14+
# Base class of all exceptions in this library
15+
assert isinstance(ex, Error)
16+
17+
# Base class of type errors
18+
assert isinstance(ex, TypeError)

0 commit comments

Comments
 (0)