Commit 66e11276 authored by Kirill Smelkov's avatar Kirill Smelkov

golang: Make sure that pychan != pychan works correctly

Pychan provides __eq__ (see 2c8063f4 "*: Channels must be compared by
==, not by "is" even for nilchan"), but does not provide __ne__. At the
same time in 17798442 (golang: Expose error at Py level) we had to
define both pyerror.__eq__ and pyerror.__ne__ because without __ne__
pyerror != pyerror was not working correctly.

As it turns out pychan != pychan already works ok, because pychan does
not have base class and for that case cython automatically generates
__ne__ based on __eq__:

    https://github.com/cython/cython/blob/0.29.14-629-ga73815042/Cython/Compiler/ModuleNode.py#L1963-L1976
    https://github.com/cython/cython/commit/b75d2942afab

Add corresponding comment and extend tests to make sure it is indeed so.
parent a9345a98
...@@ -298,6 +298,8 @@ cdef class pychan: ...@@ -298,6 +298,8 @@ cdef class pychan:
# pychan == pychan # pychan == pychan
def __hash__(pychan pych): def __hash__(pychan pych):
return <Py_hash_t>pych._ch return <Py_hash_t>pych._ch
# NOTE __ne__ not needed: pychan does not have base class and for that
# case cython automatically generates __ne__ based on __eq__.
def __eq__(pychan a, object rhs): def __eq__(pychan a, object rhs):
if not isinstance(rhs, pychan): if not isinstance(rhs, pychan):
return False return False
......
...@@ -889,24 +889,27 @@ def test_chan_dtype_misc(dtype): ...@@ -889,24 +889,27 @@ def test_chan_dtype_misc(dtype):
assert nilch is nilchan assert nilch is nilchan
assert hash(nilch) == hash(nilchan) assert hash(nilch) == hash(nilchan)
assert nilch == nilch # nil[X] == nil[X] assert (nilch == nilch) # nil[X] == nil[X]
assert nilch == nilchan # nil[X] == nil[*] assert not (nilch != nilch)
assert nilchan == nilch # nil[*] == nil[X] assert (nilch == nilchan) # nil[X] == nil[*]
assert not (nilch != nilchan)
assert (nilchan == nilch) # nil[*] == nil[X]
assert not (nilchan != nilch)
# channels can be compared, different channels differ # channels can be compared, different channels differ
assert nilch != None # just in case assert nilch != None # just in case
ch1 = chan(dtype=dtype) ch1 = chan(dtype=dtype)
ch2 = chan(dtype=dtype) ch2 = chan(dtype=dtype)
ch3 = chan() ch3 = chan()
assert ch1 != ch2; assert ch1 == ch1 assert ch1 != ch2; assert not (ch1 == ch2); assert ch1 == ch1; assert not (ch1 != ch1)
assert ch1 != ch3; assert ch2 == ch2 assert ch1 != ch3; assert not (ch1 == ch3); assert ch2 == ch2; assert not (ch2 != ch2)
assert ch2 != ch3; assert ch3 == ch3 assert ch2 != ch3; assert not (ch2 == ch3); assert ch3 == ch3; assert not (ch3 != ch3)
assert hash(nilch) != hash(ch1) assert hash(nilch) != hash(ch1)
assert hash(nilch) != hash(ch2) assert hash(nilch) != hash(ch2)
assert hash(nilch) != hash(ch3) assert hash(nilch) != hash(ch3)
assert nilch != ch1 assert nilch != ch1; assert not (nilch == ch1)
assert nilch != ch2 assert nilch != ch2; assert not (nilch == ch2)
assert nilch != ch3 assert nilch != ch3; assert not (nilch == ch3)
# .nil on chan instance XXX doesn't work (yet ?) # .nil on chan instance XXX doesn't work (yet ?)
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment