Message93171
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))". |
|
Date |
User |
Action |
Args |
2009-09-27 14:23:55 | milko.krachounov | set | recipients:
+ milko.krachounov, georg.brandl |
2009-09-27 14:23:55 | milko.krachounov | set | messageid: <1254061435.03.0.676892081826.issue7006@psf.upfronthosting.co.za> |
2009-09-27 14:23:53 | milko.krachounov | link | issue7006 messages |
2009-09-27 14:23:52 | milko.krachounov | create | |
|