Brett Cannon added the comment:

What David said. =)

The fact that the key is the first value from args is almost happenstance as 
the exception message is customized in __str__() and not in what is passed to 
the exception. But what if I had defined __getattr__ or __getattribute__ and 
had some prefix requirement? It would be more helpful to say ``KeyError("{!r} 
does not start with py_".format(key))`` which breaks your args[0] usage but is 
a much more descriptive message and has no defined way to provide the key as an 
attribute.

It's basically "explicit is better than implicit" since there is no API 
guarantee that the first thing in 'args' for KeyError will in actuality be the 
key.

----------

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

Reply via email to