[Python-3000] A plus for naked unbound methods
mrs at mythic-beasts.com
Mon Oct 6 18:50:34 CEST 2008
Terry Reedy <tjreedy at udel.edu> wrote:
> I have seen a couple of objections to leaving unbound methods naked (as
> functions) when retrieved in 3.0. Here is a plus.
> A c.l.p poster reported that 2.6 broke his code because the addition of
> default rich comparisons to object turned tests like hassattr(ob,
> '__lt__') from False to True.
For the record, the post is:
> The obvious fix ob.__lt__ == object.__lt__ does not work because
> wrapping makes it always False, even when conceptually true. In
> 3.0, that equality test works. (I pointed him to 'object' in
> repr(ob.__lt__) as a workaround. Others posted others.)
Assuming ob is an instance object, ob.__lt__ will give you a bound
method (taking 1 argument) which you would never expect to compare as
equal to object.__lt__ (taking 2 arguments). So the presence or
absence of unbound methods makes no difference here.
More information about the Python-3000