[Python-ideas] comparison of operator.itemgetter objects
Steven D'Aprano
steve at pearwood.info
Mon Apr 2 11:38:05 CEST 2012
Max Moroz wrote:
> Currently, __eq__() method is not defined in class operator.itemgetter,
> hence non-identical itemgetter objects compare as non-equal.
>
> I wanted to propose defining __eq__() method that would return the result
> of comparison for equality of the list of arguments submitted at
> initialization. This would make operator.itemgetter('name') compare as
> equal to operator.itemgetter('name').
In general, I think that having equality tests fall back on identity test is
so rarely what you actually want that sometimes I wonder why we bother.
In this case I was going to say just write your own subclass, but:
py> from operator import itemgetter
py> class MyItemgetter(itemgetter):
... pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: type 'operator.itemgetter' is not an acceptable base type
--
Steven
More information about the Python-ideas
mailing list