[Python-3000] callable()

Walter Dörwald walter at livinglogic.de
Thu Jul 20 13:32:12 CEST 2006


Guido van Rossum wrote:
> On 7/18/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>> Andrew Koenig wrote:
>>
>>> I am uncomfortable about exposing the implementation this way, if only
>>> because it would require fixing the equivalence between callable() and
>>> hasattr(obj, '__call__') for all time.
>> I don't see anything bad about fixing that equivalence.
>> I regard the fact that it *wasn't* fixed before as a
>> language design bug that Py3k will hopefully fix.
> 
> I seem to recall fixing it. Are there still callable objects without a
> __call__ attribute?

I don't know about __call__, but str and unicode don't have __iter__,
list, tuple and dict do:

Python 2.5b2 (r25b2:50512, Jul 20 2006, 13:27:27)
[GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> list.__iter__
<slot wrapper '__iter__' of 'list' objects>
>>> tuple.__iter__
<slot wrapper '__iter__' of 'tuple' objects>
>>> dict.__iter__
<slot wrapper '__iter__' of 'dict' objects>
>>> str.__iter__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'str' has no attribute '__iter__'
>>> unicode.__iter__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'unicode' has no attribute '__iter__'

Should that be fixed too?

Servus,
   Walter


More information about the Python-3000 mailing list