Skip to content

Instantly share code, notes, and snippets.

@aaronasterling
aaronasterling / argspecvalid.py
Created January 30, 2011 03:55
Checks argument sequence and mapping to make sure it's acceptable to call a given function with them. By request.
import types
ARGS_FLAG = 4
KWARGS_FLAG = 8
def valid(f, args, kwargs):
def dummy():
pass
import gc
import sys
def giveupthefunc():
code = sys._getframe(1).f_code
functype = type(lambda: 0)
for func in gc.get_referrers(code):
if type(func) is functype and getattr(func, "func_code", None) is code:
return func
import itertools
def pyfunc_fastest(x):
t = []
lenList = len(x)
extend = t.extend
for l in xrange(0, lenList):
extend([x[l]] * (lenList - l))
def pyfunc_iadd(x):
def with_intern():
def a():
return 'foo'
def b():
return 'foo'
return a() is b()
print(with_intern()) # True
def with_no_intern():
import itertools
test_strings = {}
def make_harness(args, base_setup, default_run="{0}", default_setup=''):
""" Creates a decorator to create command strings for timeit.Timer """
def test(run=default_run, setup=default_setup):
def dec(f):
name = f.__name__