[Python-Dev] Patch: AttributeError and NameError: second attempt.
Martin v. Loewis
Sun, 28 May 2000 12:34:01 +0200
[thread moved, since I can't put in proper References headers, anyway,
just by looking at the archive]
> 1) I rewrite the stuff that went into exceptions.py in C, and stick it
> in the _exceptions module. I don't much like this idea, since it
> kills the advantage noted above.
>2) I leave the stuff that's in C already in C. I add C __str__ methods
> to AttributeError and NameError, which dispatch to helper functions
> in the python 'exceptions' module, if that module is available.
>Which is better, or is there a third choice available?
There is a third choice: Patch AttributeError afterwards. I.e. in
AttributeError.__str__ = _AttributeError_str
> This kind of user-friendliness should really be in the tools, not in
> the core language implementation!
And I think Nick's patch exactly follows this guideline. Currently,
the C code raising AttributeError tries to be friendly, formatting a
string, and passing it to the AttributeError.__init__. With his patch,
the AttributeError just gets enough information so that tools later
can be friendly - actually printing anything is done in Python code.
> I see no problem with the functionality from Nick's patch; this is
> exactly te sort of thing what's needed, including at the basic
> interactive prompt.
I agree. Much of the strength of this approach is lost if it only
works inside tools. When I get an AttributeError, I'd like to see
right away what the problem is. If I had to fire up IDLE and re-run it
first, I'd rather stare at my code long enough to see the problem.