New submission from Milko Krachounov <pyt...@milko.3mhz.net>: 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))". ---------- assignee: georg.brandl components: 2to3 (2.x to 3.0 conversion tool), Documentation, Interpreter Core messages: 93171 nosy: georg.brandl, milko.krachounov severity: normal status: open title: The replacement suggested for callable(x) in py3k is not equivalent type: behavior versions: Python 2.6, Python 3.0, Python 3.1 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue7006> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com