[Python-Dev] Re: New bug in function object hash() and comparisons

Guido van Rossum guido@digicool.com
Sat, 27 Jan 2001 12:49:16 -0500


> >>>>> "GvR" == Guido van Rossum <guido@digicool.com> writes:
> 
>     GvR> Clearly, something changed.  I'm pretty sure it's the
>     GvR> function attributes.
> 
> Actually no.  func_code is used in func_hash() but somewhere in the
> Python 1.6 cycle, func_code was made assignable.

Argh!  You're right.

>     GvR> Either the function attributes shouldn't be used in comparing
>     GvR> function objects, or hash() on functions should be
>     GvR> unimplemented, or comparison on functions should use simple
>     GvR> pointer compares.
> 
>     GvR> What's the right solution?
> 
> We should definitely continue to allow functions as keys to
> dictionaries, but probably just remove func_code as an input to the
> function's hash.

OK, that settles it.  There's not much point in having a function
compare do anything besides a pointer comparison when the code objects
aren't compared.  (Two completely different functions could compare
equal e.g. if they has the same attribute dict.)  So we should just
punt, and compare functions by object pointer.

The proper way to do this is to *delete* func_hash and func_compare
from funcobject.c -- the default comparison will take care of this.

--Guido van Rossum (home page: http://www.python.org/~guido/)