[Python-Dev] __getattr__ and new style classes
Nick Coghlan
ncoghlan at gmail.com
Thu Oct 9 13:53:37 CEST 2008
Kristján Valur Jónsson wrote:
> Running regular python code through a profiler, and especially code that relies much on the use of
> __getattr__() to emulate attribute access, will show hideous amounts of time spent formatting
> attribute exceptions that get thrown away.
>
> Any thoughts on how to do this better?
If the time is being spent in PyErr_Format, how far could you get adding
a dedicated function for creating AttributeErrors? Something along the
lines of:
PyErr_AttributeError(PyObject *object, PyObject *attr_name)
It would then be possible to modify AttributeError to have obj_type and
attr_name attributes (holding the type name and the name of the missing
attribute), so that any string formatting could be deferred until repr()
was called on the AttributeError instance.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-Dev
mailing list