In the light of this and https://github.com/python/cpython/blob/6afb730e2a8bf0b472b4c3157bcf5b44aa7e6d56/Lib/unittest/case.py#L970 (linked to from https://mail.python.org/archives/list/python-dev@python.org/message/AQRLRVY7EJT4LTOCV7CLOFK3FJJTVYYM/ )

I reckon that

*like the other code before it, `seq1 == seq2` should check for (TypeError, NotImplementedError) and fall back to by-element comparison in such a case.*

On 22.12.2020 22:50, Ivan Pozdeev via Python-Dev wrote:

Okay, I see that by "fails", you probably meant "raises this exception" rather than fails the usual way (i.e. raises an AssertionError).

On 22.12.2020 22:38, Alan G. Isaac wrote:
Here, `seq1 == seq2` produces a boolean array (i.e., an array of boolean values).
hth, Alan Isaac


On 12/22/2020 2:28 PM, Ivan Pozdeev via Python-Dev wrote:

You sure about that? For me, bool(np.array) raises an exception:

In [12]: np.__version__ Out[12]: '1.19.4'

In [11]: if [False, False]==np.array([False, False]): print("foo") <...> ValueError: The truth value of an array with more than one element is ambiguous.
Use a.any() or a.all()





On 22.12.2020 21:52, Alan G. Isaac wrote:
The following test fails because because `seq1 == seq2` returns a (boolean) NumPy array whenever either seq is a NumPy array.

import unittest import numpy as np unittest.TestCase().assertSequenceEqual([1.,2.,3.], np.array([1.,2.,3.]))

I expected `unittest` to rely only on features of a `collections.abc.Sequence`, which based on https://docs.python.org/3/glossary.html#term-sequence, I believe are satisfied by a NumPy array. Specifically, I see no requirement that a sequence implement __eq__ at all much less in any particular way.

In short: a test named `assertSequenceEqual` should, I would think, work for any sequence and therefore (based on the available documentation) should not depend on the class-specific implementation of __eq__.

Is that wrong?

Thank you, Alan Isaac _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/6Z43SU2RPIHTRABYAXBOGRKWGTLIFJYK/ Code of Conduct: http://python.org/psf/codeofconduct/

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/74CUML37OCQXXKMVUFZORMSCOYP2W5GH/
Code of Conduct: http://python.org/psf/codeofconduct/
-- 
Regards,
Ivan

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/MKNN64A4JFKSBG37KZJ4HFYQ5TIE35AX/
Code of Conduct: http://python.org/psf/codeofconduct/
-- 
Regards,
Ivan