py/objarray: Turn on MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE for memoryview.
And add corresponding tests. Fixes #5674 (comparison of memoryview against bytes).
This commit is contained in:
parent
2d800c77a0
commit
3ccce89b83
|
@ -573,6 +573,7 @@ const mp_obj_type_t mp_type_bytearray = {
|
|||
#if MICROPY_PY_BUILTINS_MEMORYVIEW
|
||||
const mp_obj_type_t mp_type_memoryview = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE,
|
||||
.name = MP_QSTR_memoryview,
|
||||
.make_new = memoryview_make_new,
|
||||
.getiter = array_iterator_new,
|
||||
|
|
|
@ -107,3 +107,21 @@ try:
|
|||
memoryview(b'a').noexist
|
||||
except AttributeError:
|
||||
print('AttributeError')
|
||||
|
||||
# equality
|
||||
print(memoryview(b'abc') == b'abc')
|
||||
print(memoryview(b'abc') != b'abc')
|
||||
print(memoryview(b'abc') == b'xyz')
|
||||
print(memoryview(b'abc') != b'xyz')
|
||||
print(b'abc' == memoryview(b'abc'))
|
||||
print(b'abc' != memoryview(b'abc'))
|
||||
print(b'abc' == memoryview(b'xyz'))
|
||||
print(b'abc' != memoryview(b'xyz'))
|
||||
print(memoryview(b'abcdef')[2:4] == b'cd')
|
||||
print(memoryview(b'abcdef')[2:4] != b'cd')
|
||||
print(memoryview(b'abcdef')[2:4] == b'xy')
|
||||
print(memoryview(b'abcdef')[2:4] != b'xy')
|
||||
print(b'cd' == memoryview(b'abcdef')[2:4])
|
||||
print(b'cd' != memoryview(b'abcdef')[2:4])
|
||||
print(b'xy' == memoryview(b'abcdef')[2:4])
|
||||
print(b'xy' != memoryview(b'abcdef')[2:4])
|
||||
|
|
Loading…
Reference in New Issue