Skip to content

Commit b8d7b2a

Browse files
authored
Use abstract Container type for in operations (#9)
1 parent 151e961 commit b8d7b2a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

magic_filter/magic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import operator
22
import re
33
from functools import wraps
4-
from typing import Any, Callable, Optional, Pattern, Sequence, Set, Tuple, Type, TypeVar, Union
4+
from typing import Any, Callable, Container, Optional, Pattern, Tuple, Type, TypeVar, Union
55

66
from magic_filter.exceptions import RejectOperations, SwitchModeToAll, SwitchModeToAny
77
from magic_filter.operations import (
@@ -221,10 +221,10 @@ def is_(self: MagicT, value: Any) -> MagicT:
221221
def is_not(self: MagicT, value: Any) -> MagicT:
222222
return self._extend(CombinationOperation(right=value, combinator=operator.is_not))
223223

224-
def in_(self: MagicT, iterable: Union[Sequence[Any], Set[Any]]) -> MagicT:
224+
def in_(self: MagicT, iterable: Container[Any]) -> MagicT:
225225
return self._extend(FunctionOperation(in_op, iterable))
226226

227-
def not_in(self: MagicT, iterable: Union[Sequence[Any], Set[Any]]) -> MagicT:
227+
def not_in(self: MagicT, iterable: Container[Any]) -> MagicT:
228228
return self._extend(FunctionOperation(not_in_op, iterable))
229229

230230
def contains(self: MagicT, value: Any) -> MagicT:

magic_filter/util.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
from typing import Any, Sequence, Set, Union
1+
from typing import Any, Container
22

33

4-
def in_op(a: Union[Sequence[Any], Set[Any]], b: Any) -> bool:
4+
def in_op(a: Container[Any], b: Any) -> bool:
55
try:
66
return b in a
77
except TypeError:
88
return False
99

1010

11-
def not_in_op(a: Union[Sequence[Any], Set[Any]], b: Any) -> bool:
11+
def not_in_op(a: Container[Any], b: Any) -> bool:
1212
try:
1313
return b not in a
1414
except TypeError:
1515
return False
1616

1717

18-
def contains_op(a: Any, b: Union[Sequence[Any], Set[Any]]) -> bool:
18+
def contains_op(a: Any, b: Container[Any]) -> bool:
1919
try:
2020
return a in b
2121
except TypeError:
2222
return False
2323

2424

25-
def not_contains_op(a: Any, b: Union[Sequence[Any], Set[Any]]) -> bool:
25+
def not_contains_op(a: Any, b: Container[Any]) -> bool:
2626
try:
2727
return a not in b
2828
except TypeError:

0 commit comments

Comments
 (0)