<div dir="ltr"><div>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 (<a href="https://mail.python.org/pipermail/python-dev/2016-March/143603.html">https://mail.python.org/pipermail/python-dev/2016-March/143603.html</a>), I have decided to propose a revolutionary idea: safe mock objects.</div><div><br></div><div>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):</div><div><br></div><div><br></div><div>a = 1</div><div>b = None</div><div>c = a + b # Returns a _frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8</div><div>print(c) # Prints the empty string.</div><div>d = c+1 # All operations on `_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8`'s return a new one.</div><div>e = <a href="http://d.xyz">d.xyz</a>(1, 2, 3) # `e` is now a `_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8`.</div><div>def f():</div><div> assert 0 # Causes the function to return a `_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8`.</div><div> raise 123 # Does the same thing.</div><div>print(L) # L is undefined, so it becomes a `_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8`.</div><div><br></div><div><br></div><div>Safe mock objects are obviously the Next Error Handling Revolution ™. Unicode</div><div>errors now simply disappear and return more `_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8`s.</div><div><br></div><div>As for `try` and `catch` (protest the naming of `except`!!) statements, they will</div><div>be completely ignored. The `try`, `except`, and `finally` bodies will all be</div><div>executed in sequence, except that printing and returning values with an `except`</div><div>statement does nothing:</div><div><br></div><div><br></div><div>try:</div><div> xyz = None.a # `xyz` becomes a `_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8`.</div><div>except:</div><div> print(123) # Does nothing.</div><div> return None # Does nothing.</div><div>finally:</div><div> return xyz # Returns a `_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8`.</div><div><br></div><div><br></div><div>Aggressive error handling (as shown in PanicSort [<a href="https://xkcd.com/1185/">https://xkcd.com/1185/</a>]) that does destructive actions (such as `rm -rf /`) will always execute the destructive code, encouraging more honest development.</div><div><br></div><div>In addition, due to errors simply being ignored, nothing can ever quite go wrong.</div><div>All discussions about a safe navigation operator can now be immediately halted,</div><div>since any undefined attributes will simply return a `_frozensafemockobjectimplementation.SafeMockObjectThatIsIncludedWithPython8`.</div><div><br></div><div>Although I have not yet destroy--I mean, improved CPython to allow for this</div><div>amazing idea, I have created a primitive implementation of the `_frozensafemockobjectimplementation` module:</div><div><br></div><div><a href="https://github.com/kirbyfan64/_frozensafemockobjectimplementation">https://github.com/kirbyfan64/_frozensafemockobjectimplementation</a></div><div><br></div><div>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™.</div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr">Ryan</div><div dir="ltr">[ERROR]: Your autotools build scripts are 200 lines longer than your program. Something’s wrong.<br></div><div dir="ltr"><div><a href="http://kirbyfan64.github.io/" target="_blank">http://kirbyfan64.github.io/</a><div style="display:inline-block;width:16px;height:16px"> </div></div></div></div></div></div></div></div>
</div>