[issue8297] AttributeError message text should include module name

Ray.Allen report at bugs.python.org
Tue Apr 6 15:14:45 CEST 2010


Ray.Allen <ysj.ray at gmail.com> added the comment:

This patch makes the AttributeError message generated from getting attributes from module object more helpful, that is, print the module name. Now the error message is:
  module object 'mod_name' has no attribute 'xxx'
Instead of:
  'module' object has no attribute 'xxx'

In this patch, I add a function PyObject_GenericFindAttr(), which is almost the same as PyObject_GenericGetAttr(), except that return NULL instead of setting the exception, and make PyObject_GenericGetAttr() call this function and setting exception in the case of NULL return value. Through this, each type can custom its own AttributeError message, while using the uniform process of getting the attribute in PyObject_GenericFindAttr(). For example, PyModuleType's tp_getattro is set to a new function PyModule_GetAttr(), which calls the PyObject_GenericFindAttr() can set the customed AttributeError message.

Besides, I think the super object's AttributeError message should also be improved, but I didn't include that in the patch. I don't know weather it is suitable.

----------
keywords: +patch
Added file: http://bugs.python.org/file16780/issue_8297.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8297>
_______________________________________


More information about the Python-bugs-list mailing list