File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -469,6 +469,18 @@ record_items(PyObject *o, PyObject *args)
469469}
470470
471471
472+ static int
473+ record_contains (ApgRecordObject * o , PyObject * arg )
474+ {
475+ if (!ApgRecord_CheckExact (o )) {
476+ PyErr_BadInternalCall ();
477+ return -1 ;
478+ }
479+
480+ return PySequence_Contains (o -> mapping , arg );
481+ }
482+
483+
472484static PySequenceMethods record_as_sequence = {
473485 (lenfunc )record_length , /* sq_length */
474486 0 , /* sq_concat */
@@ -477,7 +489,7 @@ static PySequenceMethods record_as_sequence = {
477489 0 , /* sq_slice */
478490 0 , /* sq_ass_item */
479491 0 , /* sq_ass_slice */
480- 0 , /* sq_contains */
492+ ( objobjproc ) record_contains , /* sq_contains */
481493};
482494
483495
Original file line number Diff line number Diff line change @@ -212,6 +212,19 @@ def test_record_hash(self):
212212 self .assertNotIn (r3 , d )
213213 self .assertIn (r4 , d )
214214
215+ def test_record_contains (self ):
216+ r = Record (R_AB , (42 , 43 ))
217+ self .assertIn ('a' , r )
218+ self .assertIn ('b' , r )
219+ self .assertNotIn ('z' , r )
220+
221+ r = Record (None , (42 , 43 ))
222+ with self .assertRaises (TypeError ):
223+ self .assertIn ('a' , r )
224+
225+ with self .assertRaises (TypeError ):
226+ type (r ).__contains__ (None , 'a' )
227+
215228 def test_record_cmp (self ):
216229 AB = collections .namedtuple ('AB' , ('a' , 'b' ))
217230
You can’t perform that action at this time.
0 commit comments