Mercurial > cpython-lru_cache-weakref
diff Objects/bytesobject.c @ 43757:2ff0e81e68fc
Patch 1171 by mfenniak -- allow subclassing of bytes.
I suspect this has some problems when the subclass is evil,
but that's for later.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sat, 03 Nov 2007 00:24:24 +0000 |
| parents | 0502a8c64ef2 |
| children | 0d462d789b18 |
line wrap: on
line diff
--- a/Objects/bytesobject.c Fri Nov 02 23:46:40 2007 +0000 +++ b/Objects/bytesobject.c Sat Nov 03 00:24:24 2007 +0000 @@ -2921,13 +2921,21 @@ static PyObject * bytes_reduce(PyBytesObject *self) { - PyObject *latin1; + PyObject *latin1, *dict; if (self->ob_bytes) latin1 = PyUnicode_DecodeLatin1(self->ob_bytes, Py_Size(self), NULL); else latin1 = PyUnicode_FromString(""); - return Py_BuildValue("(O(Ns))", Py_Type(self), latin1, "latin-1"); + + dict = PyObject_GetAttrString((PyObject *)self, "__dict__"); + if (dict == NULL) { + PyErr_Clear(); + dict = Py_None; + Py_INCREF(dict); + } + + return Py_BuildValue("(O(Ns)N)", Py_Type(self), latin1, "latin-1", dict); } static PySequenceMethods bytes_as_sequence = { @@ -3045,8 +3053,7 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ &bytes_as_buffer, /* tp_as_buffer */ - /* bytes is 'final' or 'sealed' */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ bytes_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */
