automatic type conversion for comparison operators

Russ uymqlp502 at sneakemail.com
Fri Jul 27 01:22:57 CEST 2007


I posted a message on this several days ago, but it apparently got
lost
in googlespace, so I'll try it again.

I recently discovered a bug in my code that apparently resulted from
the automatic conversion of a function pointer to an integer.

Say you have a class member function called getCount(), which
returns an integer. Now suppose you write something like

if obj.getCount < 3: ...

This is an error because the parentheses were left off. But Python
somehow compares the function pointer with an integer without
complaining. Unless there is a darn good reason for allowing
comparisons of this type (and I can't think of one), I think
Python should flag this as an Exception.




More information about the Python-list mailing list