[New-bugs-announce] [issue41397] Restore default implementation of __ne__ in Counter

Serhiy Storchaka report at bugs.python.org
Sun Jul 26 04:25:52 EDT 2020


New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:

Currently collections.Counter implements both __eq__ and __ne__ methods. The problem is that if you subclass Counter and override its __eq__ method you will need to implement also the __ne__ method. Usually you do not need to implement __ne__ because the implementation inherited from the object class does the right thing in most cases (unless you implement NumPy or symbolic expressions). Also, the Python implementation of Counter.__ne__ is a tiny bit slower than the C implementation of object.__ne__.

Counter.__ne__ was added because the implementation of __ne__ inherited from dict did not work correct for Counter. But we can just restore the default implementation:

    __ne__ = object.__ne__

Of all Python classes in the stdlib which implement __eq__ only Counter, WeakRef and some mock classes implement also __ne__. In case of Counter I think it is not necessary.

----------
components: Library (Lib)
messages: 374306
nosy: rhettinger, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Restore default implementation of __ne__ in Counter
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41397>
_______________________________________


More information about the New-bugs-announce mailing list