Getting a set of lambda functions

Terry Reedy tjreedy at udel.edu
Sun May 25 21:23:42 EDT 2008


"Martin Manns" <mmanns at gmx.net> wrote in message 
news:g1cu8n$5g4$1 at aioe.org...
| On Sun, 25 May 2008 14:39:28 -0700 (PDT)
| bearophileHUGS at lycos.com wrote:
|
| > This may have some bugs left, but it looks a bit better:
| [...]
| >         self._hash = hash(self._func.func_code) ^ \
| >                      hash(tuple(signature[0]) + tuple(signature[1:3]))
| >     def __eq__(self, other):
| >         return self._func.func_code == other._func.func_code and \
| >                getargspec(self._func) == getargspec(other._func)
| >     def __hash__(self):
| >         return self._hash
| >     def __call__(self, *args, **kwargs):
| >         return self._func(*args, **kwargs)
| >
| > I haven't put a full hashing of getargspec(self._func) too into the
| > __init__() because it may contain too much nested unhashable
| > structures, but the __eq__() is able to tell them apart anyway, with
| > some collisions.
|
| Looking at a function:
|
| >>> a=lambda x:x
| >>> dir(a)
| ['__call__', '__class__', '__delattr__', '__dict__', '__doc__',
| '__get__', '__getattribute__', '__hash__', '__init__', '__module__',
| '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
| '__setattr__', '__str__', 'func_closure', 'func_code', 'func_defaults',
| 'func_dict', 'func_doc', 'func_globals', 'func_name']
|
| Should func_globals and func_name also be taken into account for
| __eq__()?

It depends on what *you* want == to mean.

tjr






More information about the Python-list mailing list