[issue41397] Restore default implementation of __ne__ in Counter

2020-10-19 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
resolution:  -> not a bug
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41397] Restore default implementation of __ne__ in Counter

2020-07-26 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

> The current code returns NotImplemented for non-Counter.
> If we want to implement equality comparison with other 
> class we have to override __ne__.

I'm fine with that.  It is not an undue burden and it provides a nudge to be 
explicit and intentional about the decision.

Setting __ne__ = object.__ne__ is a neat trick, but it is surprising given
Counter's __mro__ and it loses the helpful docstring describing the effect of 
zero counts.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41397] Restore default implementation of __ne__ in Counter

2020-07-26 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

The current code returns NotImplemented for non-Counter. If we want to 
implement equality comparison with other class we have to override __ne__.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41397] Restore default implementation of __ne__ in Counter

2020-07-26 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

> The problem is that if you subclass Counter and override 
> its __eq__ method you will need to implement also the
> __ne__ method. 

I don't think that is true.  The current code for __ne__ calls "==" and inverts 
the result.

Also, the docstring for the current __ne__ code is useful because it documents 
the effect of missing counts.  That information would be lost with the PR.

--
assignee:  -> rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41397] Restore default implementation of __ne__ in Counter

2020-07-26 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
keywords: +patch
pull_requests: +20768
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21627

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41397] Restore default implementation of __ne__ in Counter

2020-07-26 Thread Serhiy Storchaka


New submission from Serhiy Storchaka :

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com