Show off your Python chops and compete with others

Tim Chase python.list at
Fri Nov 8 05:05:14 CET 2013

On 2013-11-07 21:18, Roy Smith wrote:
> It's not a shifting goalpost.  My original statement was that:
> def foo():
>    raise Exception
> defines a function which 1) has no explicit return statement and 2)
> does not return None.  I stand by that statement.  There is no
> possible codepath, no possible calling sequence, no possible
> execution environment, which will cause that function to return
> None.

Well, for varying definitions of "that function", you can do

>>> def unerr(fn):
...     def wrapper(*args, **kwargs):
...             try:
...                     fn(*args, **kwargs)
...             except:
...                     return None
...     return wrapper
>>> @unerr
... def foo():
...     raise Exception
>>> print foo()


Beyond that, I'm sure one could resort to bytecode hacking to have
"that function" skip the raise...


More information about the Python-list mailing list