[Python-ideas] The future of Python: fixing broken error handling in Python 8
rymg19 at gmail.com
Fri Apr 1 10:19:04 EDT 2016
Python's exception handling system is currently badly brokeTypeError:
unsupported operand type(s) for +: 'NoneType' and 'NoneType'n. Therefore,
with the recent news of the joyous release of Python 8 (
have decided to propose a revolutionary idea: safe mock objects.
A "safe" mock object (qualified name
Java-style naming was adopted for readability purposes; comments are now no
longer necessary) is a magic object that supports everything and returns
itself. Since examples speak more words than are in the Python source code,
here are some (examples, not words in the Python source code):
a = 1
b = None
c = a + b # Returns a
print(c) # Prints the empty string.
d = c+1 # All operations on
return a new one.
e = d.xyz(1, 2, 3) # `e` is now a
assert 0 # Causes the function to return a
raise 123 # Does the same thing.
print(L) # L is undefined, so it becomes a
Safe mock objects are obviously the Next Error Handling Revolution ™.
errors now simply disappear and return more
As for `try` and `catch` (protest the naming of `except`!!) statements,
be completely ignored. The `try`, `except`, and `finally` bodies will all be
executed in sequence, except that printing and returning values with an
statement does nothing:
xyz = None.a # `xyz` becomes a
print(123) # Does nothing.
return None # Does nothing.
return xyz # Returns a
Aggressive error handling (as shown in PanicSort [https://xkcd.com/1185/])
that does destructive actions (such as `rm -rf /`) will always execute the
destructive code, encouraging more honest development.
In addition, due to errors simply being ignored, nothing can ever quite go
All discussions about a safe navigation operator can now be immediately
since any undefined attributes will simply return a
Although I have not yet destroy--I mean, improved CPython to allow for this
amazing idea, I have created a primitive implementation of the
I hope you will all realize that this new idea is a drastic improvement
over current technologies and therefore support it, because we can Make
Python Great Again™.
[ERROR]: Your autotools build scripts are 200 lines longer than your
program. Something’s wrong.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas