[IPython-dev] [Ipython-svndiff] 2717 - improve callable alias inspection

Fernando Perez fperez.net@gmail....
Thu Sep 6 01:06:43 CDT 2007


On 9/5/07, ipython-svndiff@scipy.org <ipython-svndiff@scipy.org> wrote:

> +                try:
> +                    ds = "Alias to the system command:\n  %s" % obj[1]
> +                except:
> +                    ds = "Alias: " + str(obj)

What is this bare 'except' clause trying to stop?  Is it the
IndexError from obj[1] or a possible error on str()?  Catch-all naked
excepts should really be avoided except for a few occasions where they
are there as last-resort measures to prevent a full crash.  They tend
to mask the real intent of the code and hide possible unintended bugs.

We unfortunately have way too many already:

maqroll[IPython]> grep 'except:' *.py | wc -l

but at least we should try to trim them down, not add more.  Unless
this is one of those cases where the code underneath can explode in
weird ways, and a naked except is really needed.  But in such cases,
let's  in general try to at least document *why* such a catch-all is
needed.  Here's an example from OInspect:

        ds = inspect.getdoc(obj)
        # Harden against an inspect failure, which can occur with
        # SWIG-wrapped extensions.

(just below that there's another without a comment that could use one).



More information about the IPython-dev mailing list