top | item 10147699

Fuckit.py – The Python error steamroller

86 points| aburan28 | 10 years ago |github.com | reply

46 comments

order
[+] irl_zebra|10 years ago|reply
From the test suite:

def test_context_manager(): with fuckit: pass

    assert 'P' != 'NP' # proof is left as an excercise for the reader
[+] ndr|10 years ago|reply
From the implementation:

     try:
         [...]
     except IOError:
         # Worst-case scenario we can only catch errors at a granularity
         # of the whole function.
         [...]
     else:
         # If we have access to the source, we can silence errors on a
         # per-expression basis, which is "better".
         [...]
and then:

    def __exit__(self, exc_type, exc_value, traceback):
        # Returning True prevents the error from propagating. Don't silence
        # KeyboardInterrupt or SystemExit. We aren't monsters.
Brilliant.
[+] ninetax|10 years ago|reply
I've been searching for something similar I saw years ago. It was a python library that would remove "heretical" code or something like that. Any error would be "eradicated".

It was funny! There was a religious or medieval theme or something. I can never find it...

[+] ocdtrekkie|10 years ago|reply
"This module is like violence: if it doesn't work, you just need more of it."

How could anyone not love this tool?

[+] kelvin0|10 years ago|reply
It's the Serious Sam of Python programming ... moar bullets
[+] bsg75|10 years ago|reply
s/module/XML/ is another favorite
[+] avian|10 years ago|reply
In my previous life I was maintaining some backend services. One of the most common reasons for a service dying was a typo in a name in some rarely visited code path. I was tempted to write a similar module that would be a little bit smarter: when some identifier (variable, method, etc.) was not found, instead of raising an exception, try to find a similarly named thing and use that instead. I never did find a good way of implementing that.
[+] kelvin0|10 years ago|reply
How about better testing and path coverage of your code? I hope that was also explored as a way to stabilize your codebase? Otherwise your suggestion does come offa bit as 'cowboy-ish' to say the least ...
[+] mcfunley|10 years ago|reply
Visual Basic has/had this and not as a joke. It was called "On Error Resume Next."
[+] ljk|10 years ago|reply
[+] wyldfire|10 years ago|reply
There's debate in that thread whether this project is satire or not. I must admit it looks remarkably like satire, especially the test suite.

That said, I have met some developers who would find this as an advantage and might actually try to put it into use. Generally these are folks who prefer the default soldier-on-in-the-face-of-errors behavior from sh and perl.

[+] hyperion2010|10 years ago|reply
Ah, this leads to some of my favourite python bugs. Silent failures because you are catching and ignoring an error in some higher calling function where the error type that was once designed to deal with a single case is now overly broad. I've almost given up using try/catch for KeyErrors as a result.
[+] pekk|10 years ago|reply
Python uses try/except, not try/catch. The only reason to catch KeyError is to detect missing keys, so if you are trying to do that, only wrap your dict access rather than wrapping large blocks of code where anything could happen. If you are writing code to ignore errors, that is a bug in your own code, not a python bug.
[+] dacox|10 years ago|reply
The tests are gold
[+] r3bl|10 years ago|reply
I'm definitely going to use this thing!
[+] unknown|10 years ago|reply

[deleted]

[+] jMyles|10 years ago|reply
> legitimate tool

You and I have different definitions.

[+] Khao|10 years ago|reply
But this tool is not meant to be used. You should never have to write "import someReallyOffensiveModuleName" because those are jokes not meant to be used at work.
[+] ocdtrekkie|10 years ago|reply
At work you should probably never be using a tool that just ignores errors. Errors are there for a reason, and you should have a very good reason for ignoring them.
[+] collyw|10 years ago|reply
The purpose of this obviously went right over your head.