Skip to content

Commit

Permalink
Use abstract Container type for in operations (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
monosans authored Jul 26, 2023
1 parent 151e961 commit b8d7b2a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions magic_filter/magic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import operator
import re
from functools import wraps
from typing import Any, Callable, Optional, Pattern, Sequence, Set, Tuple, Type, TypeVar, Union
from typing import Any, Callable, Container, Optional, Pattern, Tuple, Type, TypeVar, Union

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

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

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

def contains(self: MagicT, value: Any) -> MagicT:
Expand Down
10 changes: 5 additions & 5 deletions magic_filter/util.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
from typing import Any, Sequence, Set, Union
from typing import Any, Container


def in_op(a: Union[Sequence[Any], Set[Any]], b: Any) -> bool:
def in_op(a: Container[Any], b: Any) -> bool:
try:
return b in a
except TypeError:
return False


def not_in_op(a: Union[Sequence[Any], Set[Any]], b: Any) -> bool:
def not_in_op(a: Container[Any], b: Any) -> bool:
try:
return b not in a
except TypeError:
return False


def contains_op(a: Any, b: Union[Sequence[Any], Set[Any]]) -> bool:
def contains_op(a: Any, b: Container[Any]) -> bool:
try:
return a in b
except TypeError:
return False


def not_contains_op(a: Any, b: Union[Sequence[Any], Set[Any]]) -> bool:
def not_contains_op(a: Any, b: Container[Any]) -> bool:
try:
return a not in b
except TypeError:
Expand Down

0 comments on commit b8d7b2a

Please sign in to comment.