Skip to content

Instantly share code, notes, and snippets.

@wolever
Created April 27, 2010 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolever/380230 to your computer and use it in GitHub Desktop.
Save wolever/380230 to your computer and use it in GitHub Desktop.
class Boomstick(Achievement):
name = "This is my Boomstick"
description = "checking in code which uses every single function " +
"in itertools"
def __init__(self):
import itertools
self.needed = set(export for export in dir(itertools)
if not export.startswith("_"))
@accept(ast.CallFunc, ("node",))
def handle_callfunc(self, node):
seen = set(needed for needed in self.needed
if needed in str(node))
self.needed = self.needed - seen
if not self.needed:
self.unlocked()
class SpelunkingInUnderpants(Achievement):
name = "Spelunking in Underpants"
description = "using 'import *' more than once in your application"
@accept(ast.From, ("names", ))
def handle_from(self, names):
if any(name[0] == "*" for name in names):
self.unlocked()
class JackBauer(Achievement):
name = "Jack Bauer"
description = "using isinstance, hasattr, getattr and func " +
"annotations for checking types in a single " +
"function."
@accept(ast.Function, ("code", ))
def handle_function(self, code):
code_str = str(code)
if all(test in code_str for test in
[ "isinstance", "hasattr", "getattr" ]):
self.unlocked()
class MountEverest(Achievement):
name = "Mount Everest"
description = "nesting conditionals within conditionals " +
"within conditionals within conditionals."
def __init__(self):
self.level = 0
@accept(ast.If, ())
def handle_if(self):
self.level += 1
if self.level > 4:
self.unlocked()
self.walk_next()
self.level -= 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment