Skip to content

Commit e656e08

Browse files
c0llab0rat0rntninja
authored andcommitted
Move MatcherSpecInvalidError to exceptions.py
1 parent 09cae76 commit e656e08

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

ipfshttpclient/exceptions.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
│ ├── EncoderMissingError
1111
│ ├── EncodingError
1212
│ └── DecodingError
13-
└── CommunicationError
14-
├── ProtocolError
15-
├── StatusError
16-
├── ErrorResponse
17-
│ └── PartialErrorResponse
18-
├── ConnectionError
19-
└── TimeoutError
13+
├── CommunicationError
14+
│ ├── ProtocolError
15+
│ ├── StatusError
16+
│ ├── ErrorResponse
17+
│ │ └── PartialErrorResponse
18+
│ ├── ConnectionError
19+
│ └── TimeoutError
20+
└── MatcherSpecInvalidError
2021
2122
"""
2223
import typing as ty
@@ -105,6 +106,22 @@ def __init__(self, encoder_name: str, original: Exception) -> None:
105106
super().__init__("Object decoding error: {}".format(original), encoder_name)
106107

107108

109+
##################
110+
# filescanner.py #
111+
##################
112+
113+
class MatcherSpecInvalidError(TypeError):
114+
"""
115+
An attempt was made to build a matcher using matcher_from_spec, but an invalid
116+
specification was provided.
117+
"""
118+
119+
def __init__(self, matcher_class: type, invalid_spec: ty.Any) -> None:
120+
super().__init__(
121+
f"Don't know how to create a {matcher_class.__name__} from spec {invalid_spec!r}"
122+
)
123+
124+
108125
###########
109126
# http.py #
110127
###########

ipfshttpclient/filescanner.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
# To encourage contributions from PyCharm users, we redefine AnyStr.
1717
#
1818
# This will get inlined if/when PyCharm no longer flags typing.AnyStr.
19+
from .exceptions import MatcherSpecInvalidError
20+
1921
AnyStr = ty.TypeVar('AnyStr', bytes, str)
2022

2123
if sys.version_info >= (3, 7): #PY37+
@@ -413,13 +415,6 @@ def should_report(self, path: AnyStr, *, is_dir: bool) -> bool:
413415
]
414416

415417

416-
class MatcherSpecInvalidError(TypeError):
417-
def __init__(self, invalid_spec: ty.Any) -> None:
418-
super().__init__(
419-
f"Don't know how to create a {Matcher.__name__} from spec {invalid_spec!r}"
420-
)
421-
422-
423418
def _require_spec(spec: ty.Optional[match_spec_t[AnyStr]]) -> match_spec_t[AnyStr]:
424419
"""
425420
Assist the type checker by narrowing the number of places accepting Optional.
@@ -502,7 +497,7 @@ def _recursive_matcher_from_spec(spec: match_spec_t[AnyStr], *,
502497
else: # Actual list of matchers (plural)
503498
return MetaMatcher(matchers)
504499
else:
505-
raise MatcherSpecInvalidError(spec)
500+
raise MatcherSpecInvalidError(Matcher, spec)
506501

507502

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

test/unit/test_filescanner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import pytest
77

88
from datetime import datetime
9+
910
from ipfshttpclient import filescanner
1011

12+
from ipfshttpclient.exceptions import MatcherSpecInvalidError
1113
from ipfshttpclient.filescanner import FSNodeEntry
1214
from ipfshttpclient.filescanner import FSNodeType
1315

@@ -164,7 +166,7 @@ def test_glob_matching(
164166

165167
@pytest.mark.parametrize('spec', [123, datetime.now()])
166168
def test_matcher_from_spec_rejects_invalid_spec_type(spec: ty.Any) -> None:
167-
with pytest.raises(filescanner.MatcherSpecInvalidError):
169+
with pytest.raises(MatcherSpecInvalidError):
168170
filescanner.matcher_from_spec(spec)
169171

170172

0 commit comments

Comments
 (0)