File tree Expand file tree Collapse file tree 3 files changed +12
-1
lines changed
Expand file tree Collapse file tree 3 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ Alternate string representation to the built-in `str` type.
1313* Write docs (see ` str ` type docs)
1414* Write docstrings
1515* Fill out setup.py
16- * Implement repr
1716* Implement iter (iterate over Unicode code points, "runes")
1817* Implement str methods
1918* Implement buffer interface?
Original file line number Diff line number Diff line change @@ -48,6 +48,13 @@ static PyObject *cstring_str(PyObject *self) {
4848 return PyUnicode_FromString (CSTRING_VALUE (self ));
4949}
5050
51+ static PyObject * cstring_repr (PyObject * self ) {
52+ PyObject * tmp = cstring_str (self );
53+ PyObject * repr = PyObject_Repr (tmp );
54+ Py_DECREF (tmp );
55+ return repr ;
56+ }
57+
5158static Py_hash_t cstring_hash (PyObject * self ) {
5259 if (CSTRING_HASH (self ) == -1 )
5360 CSTRING_HASH (self ) = _Py_HashBytes (CSTRING_VALUE (self ), Py_SIZE (self ));
@@ -196,6 +203,7 @@ static PyTypeObject cstring_type = {
196203 .tp_dealloc = cstring_dealloc ,
197204 .tp_richcompare = cstring_richcompare ,
198205 .tp_str = cstring_str ,
206+ .tp_repr = cstring_repr ,
199207 .tp_hash = cstring_hash ,
200208 .tp_as_sequence = & cstring_as_sequence ,
201209 .tp_as_mapping = & cstring_as_mapping ,
Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ def test_str():
66 assert str (result ) == 'hello, world'
77
88
9+ def test_repr ():
10+ assert repr (cstring ('"hello" "world" 🙂' )) == repr ('"hello" "world" 🙂' )
11+
12+
913def test_hash ():
1014 a = cstring ('hello' )
1115 b = cstring ('hello' )
You can’t perform that action at this time.
0 commit comments