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 ezio.melotti
Recipients ezio.melotti, georg.brandl, milko.krachounov
Date 2009-09-27.15:59:25
SpamBayes Score 5.613925e-06
Marked as misclassified No
Message-id <>
In the PEP3100 [1] there's written, in the "to be removed" list:
  "callable(): just use hasattr(x, '__call__') (?) [2] [done]"
and the note refers to a pdf [2] that instead says:
  "callable(): just call it, already"

If callable() was removed to encourage the EAFP [3] style, replacing "if
callable(x):" with "if hasattr(x, '__call__'):" is just a less-accurate
and less-readable way of doing the same (wrong) thing [4] (also note the
(?) next to the hasattr() expression).

This might be OK for automated tools like 2to3, but not for the doc and
the warning. Humans should probably replace the expression with a
try/except instead of using hasattr().
Even for 2to3 there are better and more accurate solutions though, like
the one proposed by the OP (not really readable) and isinstance(x,

(Note: what the OP said is correct for new-style classes, for old-style
classes callable() and hasattr() have the same result).

[2]: Python Regrets:
Date User Action Args
2009-09-27 15:59:28ezio.melottisetrecipients: + ezio.melotti, georg.brandl, milko.krachounov
2009-09-27 15:59:28ezio.melottisetmessageid: <>
2009-09-27 15:59:26ezio.melottilinkissue7006 messages
2009-09-27 15:59:25ezio.melotticreate