[Python-Dev] Re: [Python-checkins] python/dist/src/Doc/lib libexcs.tex,1.43,22.214.171.124
Fred L. Drake, Jr.
Tue, 27 Aug 2002 22:41:18 -0400
[Following up to a message that went to the checkins list.]
> Note change in behavior from 1.5.2. The new argument to
> NameError is an error message and not just the missing name.
Skip Montanaro writes:
> It seems to me that somewhere in the docs it would be worthwhile to state
> Messages to exceptions are not part of the Python API. Their contents
> may change from one version of Python to the next without warning and
> should not be relied on for code which will be run with multiple
> versions of the interpreter.
The catch, of course, is that it's not clear (perhaps only to me?)
that what changed was a message. I'd interpret the original behavior
(if documented, which I won't bother to check) as an API requirement.
AttributeError use to have a similar behavior; I don't know how
rigorously that's been maintained either.
In either case, I think the ideal solution to the problem of figuring
out what went wrong, from within the executing program, is for these
errors to have an attribute that identifies the missing name ("name"
would be a good name for it). KeyError could similarly have an
attribute "key". To deal with existing code, the attributes would not
be set. Additional C functions could be provided for use in code that
is modified to provide the information.
Fred L. Drake, Jr. <fdrake at acm.org>
PythonLabs at Zope Corporation