[Python-Dev] Attribute error: providing type name
Nick Coghlan
ncoghlan at gmail.com
Mon Dec 1 22:20:36 CET 2008
Alex Martelli wrote:
> I wonder if there's some desiderata left for future Python versions to
> make this standard behavior easier (for C-coded, Python-coded, and
> Cython-coded classes, ones made by SWIG, etc) without too much black
> magic...
Perhaps adding something like the following to the C API:
void PyErr_FormatAttributeError(PyObject* type, char *attr)
{
PyErr_Format(PyExc_AttributeError,
"object of type %.100s has no attribute '%.200s'",
type->tp_name, attr);
}
This could also be exposed as a class method of AttributeError itself
for use in Python code.
(Interestingly, I noticed that there are still quite a few attribute
errors at least in typeobject.c that don't provide any information on
the type of the object that is missing an attribute - they appeared to
mostly be obscure errors that will only turn up if something has gone
very strange, but they're there)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
More information about the Python-Dev
mailing list