This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2010年12月03日 16:43 by vstinner, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (8) | |||
|---|---|---|---|
| msg123263 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2010年12月03日 16:43 | |
b'abc'.partition(':') raises a confusing TypeError('expected an object with the buffer interface'): what is a buffer? what is the buffer interface?
The error comes from PyObject_AsCharBuffer() which is used by:
- bytes methods: partition, rpartition, find, index, rfind, rindex, count, translate, replace, startswith, endswith
- complex(): raise a better but incomplete error message on error ("complex() arg is not a string"), incomplete because number is not mentionned
- float(): raise a better error message on error ("float() argument must be a string or a number")
- PyArg_Parse*() with the "e" format -> posix.spawnvpe(), imp.load_compiled(), imp.load_source(), imp.load_package()
The error message should be changed to something mentioning classic Python terms. Eg. TypeError("expected bytes, bytearray or buffer compatible object").
|
|||
| msg123265 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2010年12月03日 16:49 | |
See also #6780. |
|||
| msg123266 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2010年12月03日 16:52 | |
> complex(): raise a better but incomplete error message on error
> ("complex() arg is not a string"), incomplete because number is not
> mentionned
Fixed by r86977.
|
|||
| msg124316 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2010年12月18日 20:38 | |
Victor, I think you attached msg123266 to the wrong issue. |
|||
| msg134386 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2011年04月25日 14:50 | |
+1 to Victor's proposal ("expected bytes, bytearray or buffer compatible object").
|
|||
| msg134390 - (view) | Author: Sijin Joseph (sijinjoseph) | Date: 2011年04月25日 15:17 | |
Looking at object.h the buffer interface is defined as
/* buffer interface */
typedef struct bufferinfo {
void *buf;
PyObject *obj; /* owned reference */
Py_ssize_t len;
Py_ssize_t itemsize; /* This is Py_ssize_t so it can be
pointed to by strides in simple case.*/
int readonly;
int ndim;
char *format;
Py_ssize_t *shape;
Py_ssize_t *strides;
Py_ssize_t *suboffsets;
Py_ssize_t smalltable[2]; /* static store for shape and strides of
mono-dimensional buffers. */
void *internal;
} Py_buffer;
typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
typedef struct {
getbufferproc bf_getbuffer;
releasebufferproc bf_releasebuffer;
} PyBufferProcs;
The code that's throwing that error looks like
if (pb == NULL || pb->bf_getbuffer == NULL) {
PyErr_SetString(PyExc_TypeError,
"expected an object with the buffer interface");
I would argue that the error message gives appropriate information because it is expecting the object to have a bf_getbuffer member.
Maybe the friendly error message is best handled at a higher level?
|
|||
| msg134545 - (view) | Author: Éric Araujo (eric.araujo) * (Python committer) | Date: 2011年04月27日 10:11 | |
+1 to Antoine’s +1. |
|||
| msg137332 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2011年05月30日 21:21 | |
New changeset 7ed75bb4f37c by Victor Stinner in branch 'default': Close #10616: mention bytes and bytearray in PyObject_AsCharBuffer() error http://hg.python.org/cpython/rev/7ed75bb4f37c |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:09 | admin | set | github: 54825 |
| 2011年05月30日 21:21:38 | python-dev | set | status: open -> closed nosy: + python-dev messages: + msg137332 resolution: fixed stage: resolved |
| 2011年04月27日 10:11:15 | eric.araujo | set | messages:
+ msg134545 versions: + Python 3.3 |
| 2011年04月25日 15:17:07 | sijinjoseph | set | nosy:
+ sijinjoseph messages: + msg134390 |
| 2011年04月25日 14:50:41 | pitrou | set | nosy:
+ pitrou messages: + msg134386 |
| 2011年04月25日 02:57:43 | santoso.wijaya | set | nosy:
+ santoso.wijaya |
| 2010年12月18日 20:38:35 | r.david.murray | set | nosy:
vstinner, eric.araujo, r.david.murray messages: - msg124315 |
| 2010年12月18日 20:38:25 | r.david.murray | set | nosy:
vstinner, eric.araujo, r.david.murray messages: + msg124316 |
| 2010年12月18日 20:36:53 | r.david.murray | set | nosy:
+ r.david.murray messages: + msg124315 |
| 2010年12月04日 15:31:14 | eric.araujo | set | nosy:
+ eric.araujo |
| 2010年12月03日 16:52:07 | vstinner | set | messages: + msg123266 |
| 2010年12月03日 16:49:04 | vstinner | set | messages: + msg123265 |
| 2010年12月03日 16:43:34 | vstinner | create | |