mirror of
https://github.com/python/cpython.git
synced 2025-07-29 14:15:07 +00:00
replace callable()
This commit is contained in:
parent
0c8bee6393
commit
de0559998f
7 changed files with 18 additions and 18 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue