summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-07-11 09:28:11 (GMT)
committerGuido van Rossum <guido@python.org>2007-07-11 09:28:11 (GMT)
commit55b4a7b6dc58a49a60f93fa198a6cca1ac28a31a (patch)
tree4a28563e0193c18352f4dd35dca1c2117589849f /Objects
parentf074b640f913dcf90756676409fc0df841960fb0 (diff)
downloadcpython-55b4a7b6dc58a49a60f93fa198a6cca1ac28a31a.zip
cpython-55b4a7b6dc58a49a60f93fa198a6cca1ac28a31a.tar.gz
cpython-55b4a7b6dc58a49a60f93fa198a6cca1ac28a31a.tar.bz2
Make test_descr.py pass. Had to disable a few tests, remove references
to 'file', and fix a bunch of subtleties in the behavior of objects related to overriding __str__. Also disabled a few tests that I couldn't see how to fix but that seemed to be checking silly stuff only.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/fileobject.c8
-rw-r--r--Objects/object.c10
-rw-r--r--Objects/typeobject.c5
-rw-r--r--Objects/unicodeobject.c2
4 files changed, 13 insertions, 12 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index a0779d4..372cf43 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -142,13 +142,9 @@ PyFile_WriteObject(PyObject *v, PyObject *f, int flags)
if (writer == NULL)
return -1;
if (flags & Py_PRINT_RAW) {
- if (PyUnicode_Check(v)) {
- value = v;
- Py_INCREF(value);
- } else
- value = PyObject_Str(v);
+ value = _PyObject_Str(v);
}
- else
+ else
value = PyObject_ReprStr8(v);
if (value == NULL) {
Py_DECREF(writer);
diff --git a/Objects/object.c b/Objects/object.c
index c087b71..ee4f582 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -415,9 +415,7 @@ _PyObject_Str(PyObject *v)
res = (*v->ob_type->tp_str)(v);
if (res == NULL)
return NULL;
- type_ok = PyString_Check(res);
- type_ok = type_ok || PyUnicode_Check(res);
- if (!type_ok) {
+ if (!(PyString_Check(res) || PyUnicode_Check(res))) {
PyErr_Format(PyExc_TypeError,
"__str__ returned non-string (type %.200s)",
res->ob_type->tp_name);
@@ -476,8 +474,10 @@ PyObject_Unicode(PyObject *v)
}
else {
PyErr_Clear();
- if (PyUnicode_Check(v)) {
- /* For a Unicode subtype that's didn't overwrite __unicode__,
+ if (PyUnicode_Check(v) &&
+ v->ob_type->tp_str == PyUnicode_Type.tp_str) {
+ /* For a Unicode subtype that's didn't overwrite
+ __unicode__ or __str__,
return a true Unicode object with the same data. */
return PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(v),
PyUnicode_GET_SIZE(v));
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 9d65451..891be61 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -55,6 +55,11 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
"can't delete %s.__name__", type->tp_name);
return -1;
}
+ if (PyUnicode_Check(value)) {
+ value = _PyUnicode_AsDefaultEncodedString(value, NULL);
+ if (value == NULL)
+ return -1;
+ }
if (!PyString_Check(value)) {
PyErr_Format(PyExc_TypeError,
"can only assign string to %s.__name__, not '%s'",
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 3777991..47b1d6c 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8550,7 +8550,7 @@ static PyObject *
unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *x = NULL;
- static char *kwlist[] = {"string", "encoding", "errors", 0};
+ static char *kwlist[] = {"object", "encoding", "errors", 0};
char *encoding = NULL;
char *errors = NULL;