{
if (!PyUnicode_Check(obj)) {
PyErr_Format(PyExc_TypeError,
- "must be str, not %T", obj);
+ "must be str, not %.100s",
+ Py_TYPE(obj)->tp_name);
return -1;
}
return PyUnicode_READY(obj);
}
static int
-unicode_fromformat_write_utf8(_PyUnicodeWriter *writer, const char *str,
+unicode_fromformat_write_cstr(_PyUnicodeWriter *writer, const char *str,
Py_ssize_t width, Py_ssize_t precision)
{
/* UTF-8 */
{
/* UTF-8 */
const char *s = va_arg(*vargs, const char*);
- if (unicode_fromformat_write_utf8(writer, s, width, precision) < 0)
+ if (unicode_fromformat_write_cstr(writer, s, width, precision) < 0)
return NULL;
break;
}
}
else {
assert(str != NULL);
- if (unicode_fromformat_write_utf8(writer, str, width, precision) < 0)
+ if (unicode_fromformat_write_cstr(writer, str, width, precision) < 0)
return NULL;
}
break;
break;
}
- case 'T':
- {
- /* Object type name (tp_name) */
- PyObject *obj = va_arg(*vargs, PyObject *);
- PyTypeObject *type = Py_TYPE(obj);
- const char *type_name = type->tp_name;
- if (unicode_fromformat_write_utf8(writer, type_name, -1, -1) < 0) {
- return NULL;
- }
- break;
- }
case '%':
if (_PyUnicodeWriter_WriteCharInline(writer, '%') < 0)
return NULL;
return _PyUnicode_Copy(obj);
}
PyErr_Format(PyExc_TypeError,
- "Can't convert '%T' object to str implicitly", obj);
+ "Can't convert '%.100s' object to str implicitly",
+ Py_TYPE(obj)->tp_name);
return NULL;
}
/* Retrieve a bytes buffer view through the PEP 3118 buffer interface */
if (PyObject_GetBuffer(obj, &buffer, PyBUF_SIMPLE) < 0) {
PyErr_Format(PyExc_TypeError,
- "decoding to str: need a bytes-like object, %T found",
- obj);
+ "decoding to str: need a bytes-like object, %.80s found",
+ Py_TYPE(obj)->tp_name);
return NULL;
}
goto onError;
if (!PyUnicode_Check(unicode)) {
PyErr_Format(PyExc_TypeError,
- "'%.400s' decoder returned '%T' instead of 'str'; "
+ "'%.400s' decoder returned '%.400s' instead of 'str'; "
"use codecs.decode() to decode to arbitrary types",
- encoding, unicode);
+ encoding,
+ Py_TYPE(unicode)->tp_name);
Py_DECREF(unicode);
goto onError;
}
goto onError;
if (!PyUnicode_Check(v)) {
PyErr_Format(PyExc_TypeError,
- "'%.400s' decoder returned '%T' instead of 'str'; "
+ "'%.400s' decoder returned '%.400s' instead of 'str'; "
"use codecs.decode() to decode to arbitrary types",
- encoding, unicode);
+ encoding,
+ Py_TYPE(unicode)->tp_name);
Py_DECREF(v);
goto onError;
}
}
PyErr_Format(PyExc_TypeError,
- "'%.400s' encoder returned '%T' instead of 'bytes'; "
+ "'%.400s' encoder returned '%.400s' instead of 'bytes'; "
"use codecs.encode() to encode to arbitrary types",
- encoding, v);
+ encoding,
+ Py_TYPE(v)->tp_name);
Py_DECREF(v);
return NULL;
}
goto onError;
if (!PyUnicode_Check(v)) {
PyErr_Format(PyExc_TypeError,
- "'%.400s' encoder returned '%T' instead of 'str'; "
+ "'%.400s' encoder returned '%.400s' instead of 'str'; "
"use codecs.encode() to encode to arbitrary types",
- encoding, v);
+ encoding,
+ Py_TYPE(v)->tp_name);
Py_DECREF(v);
goto onError;
}
if (!PyBytes_Check(path) &&
PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
- "path should be string, bytes, "
- "or os.PathLike, not %T",
- arg))
- {
- Py_DECREF(path);
+ "path should be string, bytes, or os.PathLike, not %.200s",
+ Py_TYPE(arg)->tp_name)) {
+ Py_DECREF(path);
return 0;
}
path_bytes = PyBytes_FromObject(path);
}
else {
PyErr_Format(PyExc_TypeError,
- "path should be string, bytes, or os.PathLike, not %T",
- arg);
+ "path should be string, bytes, or os.PathLike, not %.200s",
+ Py_TYPE(arg)->tp_name);
Py_DECREF(path);
return 0;
}
else {
if (!PyUnicode_Check(separator)) {
PyErr_Format(PyExc_TypeError,
- "separator: expected str instance, %T found",
- separator);
+ "separator: expected str instance,"
+ " %.80s found",
+ Py_TYPE(separator)->tp_name);
goto onError;
}
if (PyUnicode_READY(separator))
item = items[i];
if (!PyUnicode_Check(item)) {
PyErr_Format(PyExc_TypeError,
- "sequence item %zd: expected str instance, %T found",
- i, item);
+ "sequence item %zd: expected str instance,"
+ " %.80s found",
+ i, Py_TYPE(item)->tp_name);
goto onError;
}
if (PyUnicode_READY(item) == -1)
if (!PyUnicode_Check(obj)) {
PyErr_Format(PyExc_TypeError,
"The fill character must be a unicode character, "
- "not %T", obj);
+ "not %.100s", Py_TYPE(obj)->tp_name);
return 0;
}
if (PyUnicode_READY(obj) < 0)
if (!PyUnicode_Check(substr)) {
PyErr_Format(PyExc_TypeError,
- "'in <string>' requires string as left operand, not %T",
- substr);
+ "'in <string>' requires string as left operand, not %.100s",
+ Py_TYPE(substr)->tp_name);
return -1;
}
if (PyUnicode_READY(substr) == -1)
if (PyUnicode_Check(sep))
return split(self, sep, maxsplit);
- PyErr_Format(PyExc_TypeError, "must be str or None, not %T", sep);
+ PyErr_Format(PyExc_TypeError,
+ "must be str or None, not %.100s",
+ Py_TYPE(sep)->tp_name);
return NULL;
}
if (PyUnicode_Check(sep))
return rsplit(self, sep, maxsplit);
- PyErr_Format(PyExc_TypeError, "must be str or None, not %T", sep);
+ PyErr_Format(PyExc_TypeError,
+ "must be str or None, not %.100s",
+ Py_TYPE(sep)->tp_name);
return NULL;
}
if (!PyUnicode_Check(substring)) {
PyErr_Format(PyExc_TypeError,
"tuple for startswith must only contain str, "
- "not %T",
- substring);
+ "not %.100s",
+ Py_TYPE(substring)->tp_name);
return NULL;
}
result = tailmatch(self, substring, start, end, -1);
if (!PyUnicode_Check(subobj)) {
PyErr_Format(PyExc_TypeError,
"startswith first arg must be str or "
- "a tuple of str, not %T", subobj);
+ "a tuple of str, not %.100s", Py_TYPE(subobj)->tp_name);
return NULL;
}
result = tailmatch(self, subobj, start, end, -1);
if (!PyUnicode_Check(substring)) {
PyErr_Format(PyExc_TypeError,
"tuple for endswith must only contain str, "
- "not %T",
- substring);
+ "not %.100s",
+ Py_TYPE(substring)->tp_name);
return NULL;
}
result = tailmatch(self, substring, start, end, +1);
if (!PyUnicode_Check(subobj)) {
PyErr_Format(PyExc_TypeError,
"endswith first arg must be str or "
- "a tuple of str, not %T", subobj);
+ "a tuple of str, not %.100s", Py_TYPE(subobj)->tp_name);
return NULL;
}
result = tailmatch(self, subobj, start, end, +1);
case 'x':
case 'X':
PyErr_Format(PyExc_TypeError,
- "%%%c format: an integer is required, not %T",
- type, v);
+ "%%%c format: an integer is required, "
+ "not %.200s",
+ type, Py_TYPE(v)->tp_name);
break;
default:
PyErr_Format(PyExc_TypeError,
- "%%%c format: a number is required, not %T",
- type, v);
+ "%%%c format: a number is required, "
+ "not %.200s",
+ type, Py_TYPE(v)->tp_name);
break;
}
return -1;