File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -33,8 +33,18 @@ def test_list_check_exact(self):
33
33
34
34
def test_list_new (self ):
35
35
list_new = _testcapi .list_new
36
- lst = list_new ()
36
+ lst = list_new (0 )
37
37
self .assertEqual (lst , [])
38
38
self .assertIs (type (lst ), list )
39
- lst2 = list_new ()
39
+ lst2 = list_new (0 )
40
40
self .assertIsNot (lst2 , lst )
41
+
42
+ def test_list_size (self ):
43
+ size = _testcapi .list_size
44
+ self .assertEqual (size ([1 , 2 ]), 2 )
45
+ self .assertEqual (size (ListSubclass ([1 , 2 ])), 2 )
46
+ self .assertRaises (SystemError , size , UserList ())
47
+ self .assertRaises (SystemError , size , {})
48
+ self .assertRaises (SystemError , size , 23 )
49
+ self .assertRaises (SystemError , size , object ())
50
+ # CRASHES size(NULL)
Original file line number Diff line number Diff line change @@ -18,14 +18,22 @@ list_check_exact(PyObject* Py_UNUSED(module), PyObject *obj)
18
18
static PyObject *
19
19
list_new (PyObject * self , PyObject * obj )
20
20
{
21
- return PyList_New (obj );
21
+ return PyList_New (PyLong_AsSsize_t ( obj ) );
22
22
}
23
23
24
+ static PyObject *
25
+ list_size (PyObject * Py_UNUSED (module ), PyObject * obj )
26
+ {
27
+ NULLABLE (obj );
28
+ RETURN_SIZE (PyList_Size (obj ));
29
+ }
24
30
25
31
static PyMethodDef test_methods [] = {
26
32
{"list_check" , list_check , METH_O },
27
33
{"list_check_exact" , list_check_exact , METH_O },
28
- {"list_new" , list_new , METH_NOARGS },
34
+ {"list_new" , list_new , METH_O },
35
+ {"list_size" , list_size , METH_O },
36
+
29
37
};
30
38
31
39
int
You can’t perform that action at this time.
0 commit comments