Emanuel Barry added the comment:

Thanks for your comments Xiang. Yes, it's not equal to #27794, but it's one of 
the multiple ways to fix it, so I made a new issue about it.

The rationale between a bare `raise AttributeError` being changed is the idea 
that it carries no information, other than the fact there was an attribute 
error (it doesn't even mean the attribute doesn't exist, as it may). Also note 
that this only affects bare AttributeErrors inside of the magic methods 
dedicated to attribute lookup (and the descriptor machinery). In a regular 
function (or even just doing `foo.__getattribute__(bar)`), `raise 
AttributeError` does nothing special.

The argument "If you do want a good message, why not passing the message when 
raising?" is one I hear a lot when there's a suggestion to add a more 
convenient way to do something that can already be done. I've seen a lot of 
code (including code in the core Python distribution, both in Python and C) 
which lazily does `raise AttributeError(name)`. It's only half the information, 
and these uninformative error messages are left completely untouched by my 
patch. The patch will help reduce boilerplate in some code. I'm personally one 
of those people who go ahead and actually use the built-in error message in my 
own code, but if I can reduce the boilerplate needed while maintaining the same 
level of information and usefulness for debugging, I'll be happy.

On the other hand, the argument that Python hides away some magic is a valid 
concern. Python already has some magic in various places; the point is to 
determine whether this kind of magic is acceptable for Python and its users. I 
honestly don't know; I don't think the magic is too strong, but at the same 
time it's likely to surprise newcomers. We'll see what others think :)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27823>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to