Skip to content

Commit de05599

Browse files
committed
replace callable()
1 parent 0c8bee6 commit de05599

7 files changed

Lines changed: 18 additions & 18 deletions

File tree

Lib/distutils/dist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ def _parse_command_opts(self, parser, args):
545545
for (help_option, short, desc, func) in cmd_class.help_options:
546546
if hasattr(opts, parser.get_attr_name(help_option)):
547547
help_option_found=1
548-
if callable(func):
548+
if hasattr(func, '__call__'):
549549
func()
550550
else:
551551
raise DistutilsClassError(

Lib/encodings/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ def search_function(encoding):
123123
raise CodecRegistryError,\
124124
'module "%s" (%s) failed to register' % \
125125
(mod.__name__, mod.__file__)
126-
if not callable(entry[0]) or \
127-
not callable(entry[1]) or \
128-
(entry[2] is not None and not callable(entry[2])) or \
129-
(entry[3] is not None and not callable(entry[3])) or \
130-
(len(entry) > 4 and entry[4] is not None and not callable(entry[4])) or \
131-
(len(entry) > 5 and entry[5] is not None and not callable(entry[5])):
126+
if not hasattr(entry[0], '__call__') or \
127+
not hasattr(entry[1], '__call__') or \
128+
(entry[2] is not None and not hasattr(entry[2], '__call__')) or \
129+
(entry[3] is not None and not hasattr(entry[3], '__call__')) or \
130+
(len(entry) > 4 and entry[4] is not None and not hasattr(entry[4], '__call__')) or \
131+
(len(entry) > 5 and entry[5] is not None and not hasattr(entry[5], '__call__')):
132132
raise CodecRegistryError,\
133133
'incompatible codecs in module "%s" (%s)' % \
134134
(mod.__name__, mod.__file__)

Lib/idlelib/rpc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ def _getmethods(obj, methods):
570570
# Adds names to dictionary argument 'methods'
571571
for name in dir(obj):
572572
attr = getattr(obj, name)
573-
if callable(attr):
573+
if hasattr(attr, '__call__'):
574574
methods[name] = 1
575575
if type(obj) == types.InstanceType:
576576
_getmethods(obj.__class__, methods)
@@ -581,7 +581,7 @@ def _getmethods(obj, methods):
581581
def _getattributes(obj, attributes):
582582
for name in dir(obj):
583583
attr = getattr(obj, name)
584-
if not callable(attr):
584+
if not hasattr(attr, '__call__'):
585585
attributes[name] = 1
586586

587587
class MethodProxy(object):

Lib/imputil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def uninstall(self):
5151
self.namespace['__import__'] = self.previous_importer
5252

5353
def add_suffix(self, suffix, importFunc):
54-
assert callable(importFunc)
54+
assert hasattr(importFunc, '__call__')
5555
self.fs_imp.add_suffix(suffix, importFunc)
5656

5757
######################################################################
@@ -539,7 +539,7 @@ def __init__(self):
539539
self.suffixes = [ ]
540540

541541
def add_suffix(self, suffix, importFunc):
542-
assert callable(importFunc)
542+
assert hasattr(importFunc, '__call__')
543543
self.suffixes.append((suffix, importFunc))
544544

545545
def import_from_dir(self, dir, fqname):

Lib/lib-tk/Tix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def image_create(self, imgtype, cnf={}, master=None, **kw):
405405
elif kw: cnf = kw
406406
options = ()
407407
for k, v in cnf.items():
408-
if callable(v):
408+
if hasattr(v, '__call__'):
409409
v = self._register(v)
410410
options = options + ('-'+k, v)
411411
return master.tk.call(('image', 'create', imgtype,) + options)

Lib/lib-tk/Tkinter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ def _options(self, cnf, kw = None):
10471047
for k, v in cnf.items():
10481048
if v is not None:
10491049
if k[-1] == '_': k = k[:-1]
1050-
if callable(v):
1050+
if hasattr(v, '__call__'):
10511051
v = self._register(v)
10521052
elif isinstance(v, (tuple, list)):
10531053
nv = []
@@ -3194,7 +3194,7 @@ def __init__(self, imgtype, name=None, cnf={}, master=None, **kw):
31943194
elif kw: cnf = kw
31953195
options = ()
31963196
for k, v in cnf.items():
3197-
if callable(v):
3197+
if hasattr(v, '__call__'):
31983198
v = self._register(v)
31993199
options = options + ('-'+k, v)
32003200
self.tk.call(('image', 'create', imgtype, name,) + options)
@@ -3217,7 +3217,7 @@ def configure(self, **kw):
32173217
for k, v in _cnfmerge(kw).items():
32183218
if v is not None:
32193219
if k[-1] == '_': k = k[:-1]
3220-
if callable(v):
3220+
if hasattr(v, '__call__'):
32213221
v = self._register(v)
32223222
res = res + ('-'+k, v)
32233223
self.tk.call((self.name, 'config') + res)

Lib/timeit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def __init__(self, stmt="pass", setup="pass", timer=default_timer):
126126
if isinstance(setup, basestring):
127127
setup = reindent(setup, 4)
128128
src = template % {'stmt': stmt, 'setup': setup}
129-
elif callable(setup):
129+
elif hasattr(setup, '__call__'):
130130
src = template % {'stmt': stmt, 'setup': '_setup()'}
131131
ns['_setup'] = setup
132132
else:
@@ -135,13 +135,13 @@ def __init__(self, stmt="pass", setup="pass", timer=default_timer):
135135
code = compile(src, dummy_src_name, "exec")
136136
exec code in globals(), ns
137137
self.inner = ns["inner"]
138-
elif callable(stmt):
138+
elif hasattr(stmt, '__call__'):
139139
self.src = None
140140
if isinstance(setup, basestring):
141141
_setup = setup
142142
def setup():
143143
exec _setup in globals(), ns
144-
elif not callable(setup):
144+
elif not hasattr(setup, '__call__'):
145145
raise ValueError("setup is neither a string nor callable")
146146
self.inner = _template_func(setup, stmt)
147147
else:

0 commit comments

Comments
 (0)