File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,10 @@ static PySequenceMethods cstring_as_sequence = {
141141 .sq_contains = cstring_contains ,
142142};
143143
144+ static PyMappingMethods cstring_as_mapping = {
145+ .mp_length = cstring_len ,
146+ };
147+
144148static PyTypeObject cstring_type = {
145149 PyVarObject_HEAD_INIT (NULL , 0 )
146150 .tp_name = "cstring" ,
@@ -154,6 +158,7 @@ static PyTypeObject cstring_type = {
154158 .tp_str = cstring_str ,
155159 .tp_hash = cstring_hash ,
156160 .tp_as_sequence = & cstring_as_sequence ,
161+ .tp_as_mapping = & cstring_as_mapping ,
157162};
158163
159164static struct PyModuleDef module = {
Original file line number Diff line number Diff line change 1+ from cstring import cstring
2+
3+
4+ def test_len ():
5+ result = cstring ('hello, world' )
6+ assert len (result ) == 12
7+
You can’t perform that action at this time.
0 commit comments