diff --git a/cycler.py b/cycler.py index 8050ca9..8ec34fc 100644 --- a/cycler.py +++ b/cycler.py @@ -135,6 +135,9 @@ def __init__(self, left, right=None, op=None): self._keys = _process_keys(self._left, self._right) self._op = op + def __contains__(self, k): + return k in self._keys + @property def keys(self): """ diff --git a/test_cycler.py b/test_cycler.py index f65a4cd..9c155b4 100644 --- a/test_cycler.py +++ b/test_cycler.py @@ -328,3 +328,18 @@ def test_by_key_mul(): assert_equal(input_dict['lw'] * len(input_dict['c']), res['lw']) yield _by_key_helper, cy + + +def test_contains(): + a = cycler('a', range(3)) + b = cycler('b', range(3)) + + assert 'a' in a + assert 'b' in b + assert 'a' not in b + assert 'b' not in a + + ab = a+b + + assert 'a' in ab + assert 'b' in ab