[Python-ideas] Use `isinstance` check during exception handling
Stephen J. Turnbull
stephen at xemacs.org
Fri Nov 6 00:33:24 EST 2015
Andrew Barnert via Python-ideas writes:
> Sjoerd Job Postmus <sjoerdjob at sjec.nl> wrote:
> > It might seem troublesome to change these locations to raise
> > actual instances instead of strings, but those might actually
> > just be hidden bugs just the same.
No, I'm sure mostly they're not. They're working code that has been
there since the early days, perhaps a few from the 2.x days in
modules. Python is generally very conservative about changing working
code.
> > Do you think anyone would object if I'd go over the code looking
> > for places where type(tstate->cur_value) != tstate->cur_type and
> > propose patches for these?
I think, yes, though I don't know enough about it to object myself.
Code churn of this kind is generally frowned upon, unless you can show
that the risk of hidden bugs of the kind you refer to above is
substantially greater than the risk that *you* will introduce bugs
with your patches.
> It would be really nice if someone remembered _why_ the code is
> this way. It may be a performance issue—
Or it could be bootstrapping -- it may be that "something" can be
raised before the exception machinery is fully initialized. (On
reflection, that seems unlikely, if raise is available, BaseException
probably is too. But you never know. :)
I would guess it was discussed, decided, and pronounced in one of the
early Python 3 PEPs. (I'm sure that for Python 2 it was purely an
issue of backward compatibility.)
More information about the Python-ideas
mailing list