This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: LookupError etc. need API to get the key
Type: enhancement Stage: needs patch
Components: Interpreter Core Versions: Python 3.10
process
Status: open Resolution:
Dependencies: 2651 Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, belopolsky, georg.brandl, loewis, pitrou, rharris
Priority: normal Keywords:

Created on 2002-09-25 18:17 by gvanrossum, last changed 2022-04-10 16:05 by admin.

Messages (7)
msg60274 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-09-25 18:17
I really wish that KeyError, AttributeError,  NameError
and IndexError provided clean APIs for getting at the
missing key, name, or index.

(Suggested by Jim Fulton)
msg60275 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-09-26 18:19
Logged In: YES 
user_id=21627

For KeyError, isn't it e.args[0]?

For the others, I suggest that args[0] is the string,
args[1] is the parameter. As a result, those classes need a
__str__ which returns args[0].
msg60276 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-09-26 19:16
Logged In: YES 
user_id=6380

Yes, it's args[0] for KeyError, but Jim objected that this
is a rather obscure protocol; he would prefer to have a
designated attribute.
msg61280 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-01-20 12:28
Will this be revisited for py3k?
msg61475 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-22 01:53
I think it would be a good idea to revisit this for py3k, but I'm out of
round tuits.  Anyone else want to tackle this?  It should ideally be
done in such a way that non-core object types can also easily raise
these exceptions with the appropriate attributes, both from C and from
Python.
msg107340 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-06-08 20:16
It looks like issue2651 is the first step for this.  See msg66432. I am merging the nosy lists.
msg222419 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-06 21:37
See also #18156, #18163, #18165 and #18166, possibly others?
History
Date User Action Args
2022-04-10 16:05:42adminsetgithub: 37218
2020-10-23 18:11:42iritkatrielsetversions: - Python 3.8, Python 3.9
2020-10-22 22:55:24iritkatrielsetversions: + Python 3.8, Python 3.9, Python 3.10, - Python 3.2
2019-04-26 18:32:44BreamoreBoysetnosy: - BreamoreBoy
2014-07-06 21:37:03BreamoreBoysetnosy: + BreamoreBoy
messages: + msg222419
2010-08-05 16:21:10belopolskysetassignee: belopolsky ->
2010-06-08 20:16:51belopolskysetassignee: belopolsky
dependencies: + Strings passed to KeyError do not round trip
type: enhancement
versions: + Python 3.2, - Python 3.0
nosy: + amaury.forgeotdarc, belopolsky, pitrou, rharris

messages: + msg107340
stage: needs patch
2009-01-06 05:06:53gvanrossumsetassignee: gvanrossum -> (no value)
nosy: - gvanrossum
2008-01-22 01:53:46gvanrossumsetmessages: + msg61475
2008-01-20 12:28:07georg.brandlsetnosy: + georg.brandl
messages: + msg61280
versions: + Python 3.0
2002-09-25 18:17:08gvanrossumcreate