New submission from Florent Xicluna <florent.xicl...@gmail.com>:

Now that callable() is back in 3.2, we may replace hasattr(obj, '__call__') 
with callable(obj).

The built-in function is easier to read and gives better performance than 
attribute lookup.


$ ./python -m timeit "hasattr(None, '__call__')"
100000 loops, best of 3: 4.09 usec per loop
$ ./python -m timeit "hasattr(str, '__call__')"
1000000 loops, best of 3: 1.3 usec per loop

$ ./python -m timeit "callable(None)"
1000000 loops, best of 3: 0.299 usec per loop
$ ./python -m timeit "callable(str)"
1000000 loops, best of 3: 0.369 usec per loop

----------
components: Library (Lib)
messages: 146320
nosy: flox
priority: normal
severity: normal
status: open
title: replace hasattr(obj, '__call__') with callable(obj)
type: performance
versions: Python 3.2, Python 3.3

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13258>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to