Author milko.krachounov
Recipients georg.brandl, milko.krachounov
Date 2009-09-27.14:23:51
SpamBayes Score 0.00174315
Marked as misclassified No
Message-id <1254061435.03.0.676892081826.issue7006@psf.upfronthosting.co.za>
In-reply-to
Content
hasattr(x, '__call__') has been suggested as a replacement for
callable(x) in the documentation and in the warning when running
python2.6 with -3. It is also what 2to3 replaces it with. However, the
two are not equivalent.

1. I can add a __call__ attribute to my object with "obj.__call__ =
lambda x:x". That will not make the object callable, callable() on
Python 2.6 returns False, but hasattr(obj, '__call__') returns True.
2. I can implement a __getattr__ that returns something for every
possible attribute name. Again, this doesn't make the object callable,
nor does callable(obj) in Python 2.6 return True.

I think a closer replacement for "callable(x)" would be "'__call__' in
vars(type(x))".
History
Date User Action Args
2009-09-27 14:23:55milko.krachounovsetrecipients: + milko.krachounov, georg.brandl
2009-09-27 14:23:55milko.krachounovsetmessageid: <1254061435.03.0.676892081826.issue7006@psf.upfronthosting.co.za>
2009-09-27 14:23:53milko.krachounovlinkissue7006 messages
2009-09-27 14:23:52milko.krachounovcreate