[issue8297] AttributeError message text should include module name
Roundup Robot added the comment: New changeset d84a69b7ba72 by Ethan Furman in branch 'default': Issue8297: module attribute lookup failures now include module name in error message. http://hg.python.org/cpython/rev/d84a69b7ba72 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Changes by Benjamin Peterson benja...@python.org: -- resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Ethan Furman added the comment: Yay, 'resolved' ! -- stage: patch review - resolved ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Ethan Furman added the comment: Mostly new patch against 3.5 -- Added file: http://bugs.python.org/file34634/issue8297.stoneleaf.01.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Changes by Ethan Furman et...@stoneleaf.us: -- versions: +Python 3.5 -Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Ethan Furman added the comment: ysj.ray: Your patch looks good. I had to make some changes since we're now at 3.5. Before I can use your code, though, you need to sign the CLA [1]. Thanks. [1] https://www.python.org/psf/contrib/contrib-form -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Changes by Ethan Furman et...@stoneleaf.us: -- assignee: - ethan.furman versions: +Python 3.4 -Python 2.7, Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Changes by Ethan Furman et...@stoneleaf.us: -- nosy: +ethan.furman ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Amaury Forgeot d'Arc amaur...@gmail.com added the comment: I also like the idea; 3 remarks though: - the patch introduces a new function that returns a PyObject*, but returns NULL when the attribute is not found, and the caller should raise AttributeError. This convention is not standard among the Python API and dangerous IMO. This part of the patch is not necessary. PyModule_GetAttr could just call PyObject_GenericGetAttr and override the current exception with a new message. - it's not necessary to expose the function PyModule_GetAttr. It could be renamed to something like module_getattr, and be a static function. Module writers are already used to PyObject_GetAttr to access the module items, this new function brings nothing new. - a minor nit: instead of module object 'mod_name' has no attribute 'xxx' I'd prefer module 'mod_name' has no attribute 'xxx' -- nosy: +amaury.forgeotdarc ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Ray.Allen ysj@gmail.com added the comment: Amaury: Thanks for reviewing! I quite appreciate your ideas. I was not quite familiar with python source code convention at that time. Here I worked out a new patch based on your ideas. Since py2.7 has released, this feature can only go to py3k. So my new patch is against py3k. Hoping somebody could review it. Thanks all! By the way, I feel if module object's getattr can be customized, other types, like the super object, also needs this. -- Added file: http://bugs.python.org/file18124/issue_8297.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Daniel Urban urban.dani...@gmail.com added the comment: According to PEP 7 [1], all declarations must be at the top of a block. So you probably should move the char *mod_name_str and PyModuleObject *module declarations to the beginning of the function's body. [1] http://www.python.org/dev/peps/pep-0007/ -- nosy: +durban ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Ray.Allen ysj@gmail.com added the comment: Thanks! durban. Here is the updated patch fixing such problem. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Changes by Daniel Diniz aja...@gmail.com: -- nosy: +ajaksu2 stage: unit test needed - patch review ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Ray.Allen ysj@gmail.com added the comment: The unittest of this patch. -- Added file: http://bugs.python.org/file16815/issue_8297_test.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
R. David Murray rdmur...@bitdance.com added the comment: This is a feature request, so it only applies to unreleased versions. It'll be up to Benjamin whether it can go into 2.7, if the change is approved, since 2.7 is now technically in feature freeze. The patch also needs unit tests. I do like the idea of making the error messages more specific. I have not reviewed the patch itself. -- components: +Interpreter Core -Library (Lib) nosy: +r.david.murray stage: needs patch - test needed versions: +Python 3.2 -Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Ray.Allen ysj@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 rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Chris Jerdonek chris.jerdo...@gmail.com added the comment: Great -- thanks a lot for taking a stab at this! -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Changes by Chris Jerdonek chris.jerdo...@gmail.com: -- versions: +Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Ray.Allen ysj@gmail.com added the comment: Yes, I agree with this feature request. And also the super(Class, obj) call should return a reasonable AttributeError message when the requested attribute is not found in one of Class's base classes, not just 'super' object has no attribute 'xxx'. -- nosy: +ysj.ray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Ray.Allen ysj@gmail.com added the comment: In fact, there are only three types of tp_getattro functions: 1.For type objects, it is type_getattro(), in case of AttributeError, this function give the message format: type object %(type)s has no attribute %(attr)s 2.For super objects, it is super_getattro(), in case of no attribute found in one of its base class, it calls the 3'th getattr function below. 3.For the base type 'object' and other new style class, it is PyObject_GenericGetAttr(), and in case of AttributeError, this function give the message format: %(type)s object has no attribute %(attr)s So, there are only tow formats of AttributeError's exception messages: 1.type object %(type)s has no attribute %(attr)s 2.%(type)s object has no attribute %(attr)s The first one is for type objects, the second one is for all the instances objects. In most cases, these tow formats it is enough for program to display, bu t it is not well enough. Take the module objects for example, in case of AttributeError, we will always hope to know exactly which module has no attribute, not only the message: 'module object has attribute xxx'. Also for the super() call, take super(A, b).xxx() for example, if the attribute is not found in the class next to the A in b's type's mro list, PyObject_GenericGetAttr() will be called with the two arguments, the super object its self and 'xxx'. But there are only few valid attributes of a super object, like '__thisclass__', '__self__', '__self_class__'. In most cases, we don't need these attributes of a super object, what we need is the attribute of one of b's type's base types. So I think once the AttributeError is raised in PyObject_GenericGetAttr() call in the end of super_getattro(), the exception message should tell us in which base class python can not found the attribte 'xxx', but not the super object itself, although the exception is raised in the PyObject_GenericGetAttr(super obj, 'xxx'). For the solution, I think the type_getattro and super_getattro can just return NULL to indicate the attribute is not found, but for a wrapper function of this tow which is the tp_getattro for each type to raise the attribute error, with the reasonable exception message. For example, mudule type can tell which module has no attribute, super type can tell which base class has no attribute, and so on. What about others' opinion? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
Changes by Ezio Melotti ezio.melo...@gmail.com: -- nosy: +ezio.melotti priority: - low stage: - needs patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8297] AttributeError message text should include module name
New submission from Chris Jerdonek chris.jerdo...@gmail.com: It would be nice if the error message for an AttributeError could include the module name when getting from a module -- just like it does for getting from a class. This would make the message more helpful. For example, it would help in diagnosing issues like the ones mentioned in this report: http://bugs.python.org/issue7559 EXAMPLE (using latest from trunk Python 2.7a4+): import sys class TestClass(object): pass m = sys c = TestClass print CLASS: %s % c try: c.asdf except AttributeError, err: print err print \nMODULE: %s % m try: m.adsf except AttributeError, err: print err *** OUTPUT: CLASS: class '__main__.TestClass' type object 'TestClass' has no attribute 'asdf' MODULE: module 'sys' (built-in) 'module' object has no attribute 'adsf' *** The latter message could instead be (paralleling the text in the case of a class)-- module object 'sys' has no attribute 'adsf' -- components: Library (Lib) messages: 102224 nosy: cjerdonek severity: normal status: open title: AttributeError message text should include module name type: feature request versions: Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8297 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com