This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author flox
Recipients flox
Date 2011-10-24.19:46:14
SpamBayes Score 2.7763273e-05
Marked as misclassified No
Message-id <1319485575.06.0.0356181366596.issue13258@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2011-10-24 19:46:15floxsetrecipients: + flox
2011-10-24 19:46:15floxsetmessageid: <1319485575.06.0.0356181366596.issue13258@psf.upfronthosting.co.za>
2011-10-24 19:46:14floxlinkissue13258 messages
2011-10-24 19:46:14floxcreate