Exception handling wart in Python
Delaney, Timothy
tdelaney at avaya.com
Sun Nov 4 19:09:09 EST 2001
> Going back to generic nature of Python's functions, I think,
> obviously,
> most of the functions in real Python programs are not generic
> at all, even
> though from the point of view of Python compiler, they are
> generic. But
> from a higher level point of view, they're not generic.
I'll use a concrete example here.
Every single function in Python which uses a callback is very generic. It
can accept any callable object. These include functions, but include many
other objects (class objects, class instances, etc).
How would you trace the "exceptions that can be thrown" from a function such
as map()? It's callback function can do anything it pleases.
And yet, this is an incredibly simple function - almost the equivalent of:
def map (callable, seq):
l = []
for i in seq:
l.append(callable(seq))
return l
This is a very common idiom through the Python libraries.
Tim Delaney
More information about the Python-list
mailing list