Skip to content

Commit

Permalink
Add support for __contains__
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed May 4, 2013
1 parent cc3dbe2 commit 33de146
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -4,6 +4,8 @@ Changelog
3.0 (unreleased)
----------------

- Add support for `__contains__`.

- Rewrite tests as unit tests.

2.13.0 (2010-03-30)
Expand Down
3 changes: 3 additions & 0 deletions src/Record/__init__.py
Expand Up @@ -70,3 +70,6 @@ def __setattr__(self, key, value):
object.__setattr__(self, key, value)
else:
self.__setitem__(key, value)

def __contains__(self, key):
return key in self._schema
6 changes: 6 additions & 0 deletions src/Record/tests.py
Expand Up @@ -67,3 +67,9 @@ def test_sequence(self):
self.assertEqual(r[2], 7)
self.assertEqual(r.c, 7)
self.assertEqual(list(r), [1, 6, 7])

def test_contains(self):
r = R((1, 2, None))
self.assertTrue('a' in r)
self.assertTrue('c' in r)
self.assertFalse('d' in r)

0 comments on commit 33de146

Please sign in to comment.