[issue26514] Object defines '__ne__' as 'not __eq__' if '__ne__' is not implemented

2016-03-08 Thread Eryk Sun

Changes by Eryk Sun :


--
resolution:  -> works for me
stage:  -> 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



[issue26514] Object defines '__ne__' as 'not __eq__' if '__ne__' is not implemented

2016-03-08 Thread Josh Rosenberg

Josh Rosenberg added the comment:

It's not exactly what was asked for, but it's actually better (in that the 
__ne__ default implementation handles NotImplemented correctly). Per the docs 
at https://docs.python.org/3/reference/datamodel.html#object.__eq__ :

"By default, __ne__() delegates to __eq__() and inverts the result unless it is 
NotImplemented."

This feature was never backported to 2.7, but it's existed in one form or 
another for the entire 3.x line.

--
nosy: +josh.r

___
Python tracker 

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



[issue26514] Object defines '__ne__' as 'not __eq__' if '__ne__' is not implemented

2016-03-08 Thread Ethan Furman

Ethan Furman added the comment:

The following behaviour is from 3.5:

--> class Huh:
...   def __eq__(self, other):
... return other == 'blah'
... 
--> h = Huh()
--> h == 'ew'
False
--> h != 'ew'
True
--> h == 'blah'
True
--> h != 'blah'
False

Which seems to be exactly what you want.  Do you have a counter-example?

--
nosy: +ethan.furman

___
Python tracker 

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



[issue26514] Object defines '__ne__' as 'not __eq__' if '__ne__' is not implemented

2016-03-08 Thread Marc Guetg

New submission from Marc Guetg:

I propose to change __ne__ of `object` in the following form:

class NewObject(object):
def __ne__(self, other):
return not self.__eq__(other)

Currently overwriting the `__eq__` method requires also overwriting `__ne__`. 
In a vast majority of cases this results in some boilerplate code as:

(a == b) ^ (a != b) == True

to reduce surprises. Changing the default behavior still allows for the limited 
number of use cases where we want to implement __ne__ differently.


In short I propose the same behavior than __str__ and __repr__ have for __eq__ 
and __ne__.
(https://docs.python.org/3/reference/datamodel.html#object.__str__)

--
components: Interpreter Core
messages: 261385
nosy: Marc Guetg
priority: normal
severity: normal
status: open
title: Object defines '__ne__' as 'not __eq__' if '__ne__' is not implemented
type: enhancement
versions: Python 3.6

___
Python tracker 

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