diff options
| author | Dong-hee Na <donghee.na@python.org> | 2021-08-23 10:01:51 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-23 19:01:51 +0900 |
| commit | 24b63c695ae0a95b06379eaadace66735abac1e2 (patch) | |
| tree | 8bc8bbc38511c504860b494e125c232f51457638 /Objects/bytesobject.c | |
| parent | 6082bb5addab93755ab6e2bd2ed6021b391e10d1 (diff) | |
| download | cpython-git-24b63c695ae0a95b06379eaadace66735abac1e2.tar.gz | |
bpo-24234: Implement bytes.__bytes__ (GH-27901)
Diffstat (limited to 'Objects/bytesobject.c')
| -rw-r--r-- | Objects/bytesobject.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index eaedb0b568..13f94b4c82 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -1687,6 +1687,25 @@ static PyBufferProcs bytes_as_buffer = { }; +/*[clinic input] +bytes.__bytes__ +Convert this value to exact type bytes. +[clinic start generated code]*/ + +static PyObject * +bytes___bytes___impl(PyBytesObject *self) +/*[clinic end generated code: output=63a306a9bc0caac5 input=34ec5ddba98bd6bb]*/ +{ + if (PyBytes_CheckExact(self)) { + Py_INCREF(self); + return (PyObject *)self; + } + else { + return PyBytes_FromString(self->ob_sval); + } +} + + #define LEFTSTRIP 0 #define RIGHTSTRIP 1 #define BOTHSTRIP 2 @@ -2474,6 +2493,7 @@ bytes_getnewargs(PyBytesObject *v, PyObject *Py_UNUSED(ignored)) static PyMethodDef bytes_methods[] = { {"__getnewargs__", (PyCFunction)bytes_getnewargs, METH_NOARGS}, + BYTES___BYTES___METHODDEF {"capitalize", stringlib_capitalize, METH_NOARGS, _Py_capitalize__doc__}, STRINGLIB_CENTER_METHODDEF |
