FuckIt.py - The Python Error Steamroller
github.com
github.com
[0] http://en.wikipedia.org/wiki/Abstract_syntax_tree
[1] https://github.com/ajalt/fuckitpy/blob/master/fuckit.py#L70-...
https://github.com/ajalt/fuckitpy/blob/master/tests.py
def test_chaining():
fuckit(fuckit('fuckit'))
assert 'false' # Good thing this isn't PHPThanks for the links!
- does something rather novel
- does something that, to the sufficiently desperate or inept developer, might seem like a half-decent idea or a cunning shortcut
- does something that is just asking for trouble and that nobody in their right mind should do without expecting terrible, terrible things to happen
- does something that is just asking for trouble and that nobody in their right mind should do without expecting terrible, terrible things to happen
It makes Python run about like JavaScript or PHP. I guess that's accurate.In reality, even if this is satire (which I believe it is) I'm sure if enough people will know about it, at least one of them will use it seriously.
If you want to go the other way, try
window.onerror = window.close;Python has an API for inspecting the AST.
I want a fuckit.hs
Putting aside the fact that this project is probably satire, how is this a "these days" thing? Code in the bad old days was just as littered with ON ERROR RESUME NEXT, if (err) {/*this cant happen*/ return;} and catch {/*do something here*/}
As for the "these days" comment, why is it that people are repeatedly convinced that human habits have changed that drastically in their lifetimes? This "change" is the result of perspective, no more, no less.
OTOH, I would actually say that things have improved of late.
Just in the last couple of decades we've seen what I think are the first serious approaches to error handling. Think about things like the Abrahams Guarantees, or all those fun category-theoretic analyses that the functional folks keep generating.
And then the stakes have gotten higher. Thirty years ago, if a user gave a program messed-up data, then we could shake our heads and say, "Stupid user." Today, large companies put mission-critical functionality on the web, opening it up to people with both the time and the inclination to generate messed-up data in an attempt to bring the system down.
The result of all this is that, just in the last one or two decades, we've finally seen a significant number of large software packages that actually work.
And that, IMHO, is not a trivial development.
Sometimes the effort involved in "properly" initializing someone's module far outweighs whatever potential benefit you get out of the module - this seems to subvert that quite nicely.
I feel like writing some Python now.
For those who think so, try doing some machine learning, data handling code, or even web crawlers. Error tolerance is much needed.
For scientific experiments, sometimes the results of the experiment is still valuable even if there's a trivial bug (malformed row). A partially-correct execution is still more information than an unhandled exception causing an early exit.
An age appropriate name for the module could be peekaboo.
If anything, your error messages are more important then.
if for nothing else, I am in love with this for its sense of humor
On Error Resume NextAt one point in a previous life, I was the administrator for HP Quality Center at my company. On the good side, HP exposes the entire workflow in VBA (ok, I guess that isn't that good actually, but still better than black box).
On the horrible side, EVERY SINGLE FUNCTION in that application began with the line "On Error Resume Next". I quite nearly quit on the spot the first time I looked at the code. A couple years later, I would regret that decision.
https://github.com/kislyuk/ensure
(Though I know how frustrating exception juggling can get... especially when they get pickled and re-raised)
I'm sad to say I say this every time this happens to me as well.
def test_context_manager(): with fuckit: pass
assert 'P' != 'NP' # proof is left as an excercise for the reader import fuckit
from string import ascii_lowercase, digits
from random import choice, randint
def defuckify(test_fn, fn_name, n_arguments):
''' Randomly generate functions until the test passes
'''
defuckified_fn = ('def %s(' % fn_name)
for i in range(n_arguments):
arg_name = ('arg%d,' % i) if i != n_arguments else ('arg%d' % i)
defuckified_fn += arg_name
defuckified_fn += '):'
exec('def '+ fn_name + '():\n pass\n')
while not test_fn():
for i in range(randint(100,10000)):
defuckified_fn += choice(' \n,[](){}\'"=+-*/%:'+ ascii_lowercase + digits)
with fuckit:
exec(defuckified_fn)
print(defuckified_fn)
Edited to use fuckit instead of try/catchEdited again to add that it has been over an hour and it hasn't been able to make a function that returns 3
That is not a pair of words I ever thought I'd use in the same sentence. :)
EDIT: wait, you actually ran code produced from this?
Also the defuckify code I posted is not exactly right, as it was sort of a joke but it's pretty easy to fix
You could try something similar to easily produce random python code that will be correct a much higher percent of the time.
The problem was comments screwed it up since it would randomly put comments in code and comment out actual code.
edit: found it http://www.repeater-builder.com/humor/signetics-wom.pdf I love 0V +- %2
- Yippie kai yay, motherfucker.
"...and changing it [license] is allowed as long as the name is changed."
edit: i was joking :)
REALLY DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
The licence for the code itself is "0. You just DO WHAT THE FUCK YOU WANT TO." The license for the license is similar, with the caveat that you're required to change the name if you change the content. Which makes sense; we wouldn't want confusion about what the WTFPL refers to.
@fuckit def func(): problem_solved
That has to be the best piece of code I have ever seen.
just wrap the offending module and get on with your life; and in those rare (for me) instances where you still get errors, this module supports chaining syntax--declarative syntax, to say the least:
fuckit(fuckit('imported_module'))