This update brings a new feature to make it super easy to start insulting friends and enemies alike.
always_insult_me function will rejigger your environment to convert all uncaught exceptions
InsultErrors with the usual random insults and (optionally) messages. If you get sick of this
dont_always_insult_me will set things back to normal.
A little example to demonstrate:
Credit to Jacob McDonald (my colleague at Indigo Ag) for the idea and initial implementation. This feature
works by modifying the
sys.excepthook callable, which is executed just before Python fails due to an
uncaught exception. Happily, the original value of this callable is preserved as
we can easily undo the change.We simply wrap the original hook such that the exception type becomes an
but the traceback is unchanged. This is important because we want to insult people, but not fuck up
Some internals have changed as well since the last post. Most notably, error names are handled in
a much simpler way. Rather than mucking about with
__new__ and exception subclasses, we just
modify the exception
___class__.__name__ attribute during exception initialization. We still
InsultError instance, but it has a nice random name. Python really let’s you do any
damn thing you want.
Lastly, there are a few new insults in there since my last post. Still looking for contributions, of course!