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)
469
469
}
470
470
471
471
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
+
472
484
static PySequenceMethods record_as_sequence = {
473
485
(lenfunc )record_length , /* sq_length */
474
486
0 , /* sq_concat */
@@ -477,7 +489,7 @@ static PySequenceMethods record_as_sequence = {
477
489
0 , /* sq_slice */
478
490
0 , /* sq_ass_item */
479
491
0 , /* sq_ass_slice */
480
- 0 , /* sq_contains */
492
+ ( objobjproc ) record_contains , /* sq_contains */
481
493
};
482
494
483
495
Original file line number Diff line number Diff line change @@ -212,6 +212,19 @@ def test_record_hash(self):
212
212
self .assertNotIn (r3 , d )
213
213
self .assertIn (r4 , d )
214
214
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
+
215
228
def test_record_cmp (self ):
216
229
AB = collections .namedtuple ('AB' , ('a' , 'b' ))
217
230
You can’t perform that action at this time.
0 commit comments