replace callable()

This commit is contained in:
Benjamin Peterson 2009-10-09 22:05:45 +00:00
parent 0c8bee6393
commit de0559998f
7 changed files with 18 additions and 18 deletions

View file

@ -126,7 +126,7 @@ class Timer:
if isinstance(setup, basestring):
setup = reindent(setup, 4)
src = template % {'stmt': stmt, 'setup': setup}
elif callable(setup):
elif hasattr(setup, '__call__'):
src = template % {'stmt': stmt, 'setup': '_setup()'}
ns['_setup'] = setup
else:
@ -135,13 +135,13 @@ class Timer:
code = compile(src, dummy_src_name, "exec")
exec code in globals(), ns
self.inner = ns["inner"]
elif callable(stmt):
elif hasattr(stmt, '__call__'):
self.src = None
if isinstance(setup, basestring):
_setup = setup
def setup():
exec _setup in globals(), ns
elif not callable(setup):
elif not hasattr(setup, '__call__'):
raise ValueError("setup is neither a string nor callable")
self.inner = _template_func(setup, stmt)
else: