Skip to content

Commit b5965b6

Browse files
committed
Make or operation important to always call a right operand. Suppress function operation Type or Value errors.
1 parent 950148c commit b5965b6

File tree

6 files changed

+192
-121
lines changed

6 files changed

+192
-121
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ reformat:
7171
# =================================================================================================
7272

7373
test:
74-
$(py) pytest --cov=magic-filter --cov-config .coveragerc tests/
74+
$(py) pytest --cov=magic_filter --cov-config .coveragerc tests/
7575

7676
test-coverage:
7777
mkdir -p $(reports_dir)/tests/
78-
$(py) pytest --cov=magic-filter --cov-config .coveragerc --html=$(reports_dir)/tests/index.html tests/
78+
$(py) pytest --cov=magic_filter --cov-config .coveragerc --html=$(reports_dir)/tests/index.html tests/
7979
$(py) coverage html -d $(reports_dir)/coverage
8080

8181
test-coverage-report:

magic_filter/magic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
GetItemOperation,
1515
RCombinationOperation,
1616
)
17+
from magic_filter.operations.combination import ImportantCombinationOperation
1718
from magic_filter.operations.function import ImportantFunctionOperation
1819

1920
MagicT = TypeVar("MagicT", bound="MagicFilter")
@@ -122,8 +123,8 @@ def __rand__(self: MagicT, other: Any) -> MagicT:
122123

123124
def __or__(self: MagicT, other: Any) -> MagicT:
124125
if isinstance(other, MagicFilter):
125-
return self._extend(CombinationOperation.or_op(right=other))
126-
return self._extend(CombinationOperation(right=other, combinator=operator.or_))
126+
return self._extend(ImportantCombinationOperation.or_op(right=other))
127+
return self._extend(ImportantCombinationOperation(right=other, combinator=operator.or_))
127128

128129
def __ror__(self: MagicT, other: Any) -> MagicT:
129130
return self._extend(RCombinationOperation(left=other, combinator=operator.or_))

magic_filter/operations/combination.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def or_op(cls, right: "MagicFilter") -> "CombinationOperation":
2929
return cls(right=right, combinator=or_op)
3030

3131

32+
class ImportantCombinationOperation(CombinationOperation):
33+
important = True
34+
35+
3236
class RCombinationOperation(BaseOperation):
3337
__slots__ = (
3438
"left",

magic_filter/operations/function.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from functools import partial
22
from typing import Any, Callable
33

4+
from ..exceptions import RejectOperations
45
from .base import BaseOperation
56

67

@@ -11,7 +12,10 @@ def __init__(self, function: Callable[[Any], Any]) -> None:
1112
self.function = function
1213

1314
def resolve(self, value: Any, initial_value: Any) -> Any:
14-
return self.function(value)
15+
try:
16+
return self.function(value)
17+
except (TypeError, ValueError) as e:
18+
raise RejectOperations(e) from e
1519

1620
@classmethod
1721
def in_op(cls, a: Any) -> "FunctionOperation":

0 commit comments

Comments
 (0)