Exception handling wart in Python

Leo Lipelis aeoo at myrealbox.com
Thu Nov 1 19:35:46 EST 2001


Hi Pythoneers,

I'd like some help with an issue I have with Python.  Simply put, I think
having an exception mechanism is a waste if there is no tool that will let
you know which unhandled exceptions exist at point foo.  I have spoken
about this issue briefly with Neal, of the PyChecker fame, and he seemed to
agree with me.

I realize that it's a difficult problem to solve, but I think it would be
worth solving at the language level, similarly to the way it's done in
Java.  Let's say I call a function in some module,

a = some_module.func(b)

Now, what I would like, is to know as precisely as possible (but I would
be happy with an intelligent guess also), what exceptions are possible as
a result of that function call, so that I can decide which ones to handle
and which ones to not handle, etc.

Considering that in Python exceptions are matched by identity instead of
equivalence, it's possible to track all the exception flows, right?

I think relying on documentation for this is not an option.  First, there
is never a guarantee of documentation, and I would like this feature to be
guaranteed.  Second, it becomes very problematic with deeply nested
functions and inheritance.  Why should I have to search through all those
docs for something that compiler should tell me anyway?  This is just the
kind of monotonous task that needs to be done by a computer program
instead of a human.

I realize that something like PyChecker can eventually check for unhandled
exceptions, but I think this is important enough to be done at the core
language level.  I mean this should be done by a tool that's present in a
standard Python tarball.

I agree with whoever said that a race horse doesn't belong in the glue
factory.  It seems like Python is being used for serious programming, and
it seems to me, if it supports exceptions, it should support them all the
way.  It's fairly pointless to provide exceptions if you really never know
whether you handle all the relevant exceptions or not, without the ugly,
bad, and stupid except: foo() statements to catch *all* exceptions.

Leo "__who_doesnt_like_underscores_and_many_selves_at_all__" Lipelis

P.S.:  The double leading underscore is the ugliest thing I've ever seen in
language syntax.  I've been writing some Python code that uses that
feature, and man, it looks ugly.  For a language that prides itself on
indentation based code blocks for readability, double underscore is an ugly
wart that needs to be fixed.  That, and having to constantly type
self.__quax, self.__foo, self.__bar(), self.__foobar()...  That's
*SEVEN* whopping useless characters on every line.

P.P.S.: Otherwise Python is a very pleasant and productive language.



More information about the Python-list mailing list