[Python-Dev] The future of Python: fixing broken error handling in Python 8 (original) (raw)
Ryan Gonzalez rymg19 at gmail.com
Fri Apr 1 10:19:04 EDT 2016
- Previous message (by thread): [Python-Dev] Adding a Pip GUI to IDLE and idlelib (GSOC project)
- Next message (by thread): [Python-Dev] Summary of Python tracker Issues
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 ( https://mail.python.org/pipermail/python-dev/2016-March/143603.html), I have decided to propose a revolutionary idea: safe mock objects.
A "safe" mock object (qualified name
_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8
;
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
_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8
print(c) # Prints the empty string.
d = c+1 # All operations on
_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8
's
return a new one.
e = d.xyz(1, 2, 3) # e
is now a
_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8
.
def f():
assert 0 # Causes the function to return a
_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8
.
raise 123 # Does the same thing.
print(L) # L is undefined, so it becomes a
_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8
.
Safe mock objects are obviously the Next Error Handling Revolution ™.
Unicode
errors now simply disappear and return more
_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8
s.
As for try
and catch
(protest the naming of except
!!) statements,
they will
be completely ignored. The try
, except
, and finally
bodies will all be
executed in sequence, except that printing and returning values with an
except
statement does nothing:
try:
xyz = None.a # xyz
becomes a
_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8
.
except:
print(123) # Does nothing.
return None # Does nothing.
finally:
return xyz # Returns a
_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8
.
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
wrong.
All discussions about a safe navigation operator can now be immediately
halted,
since any undefined attributes will simply return a
_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8
.
Although I have not yet destroy--I mean, improved CPython to allow for this
amazing idea, I have created a primitive implementation of the
_frozensafemockobjectimplementation
module:
https://github.com/kirbyfan64/_frozensafemockobjectimplementation
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™.
-- Ryan [ERROR]: Your autotools build scripts are 200 lines longer than your program. Something’s wrong. http://kirbyfan64.github.io/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160401/d2b72a45/attachment-0001.html>
- Previous message (by thread): [Python-Dev] Adding a Pip GUI to IDLE and idlelib (GSOC project)
- Next message (by thread): [Python-Dev] Summary of Python tracker Issues
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]