Python why

>>> b"A" in b"ABC"
True
>>> ord(b"A") in b"ABC"
True
>>> b"A" in memoryview(b"ABC")
False
>>> ord(b"A") in memoryview(b"ABC")
True
@whitequark it's because of what memoryview(b"ABC")[0] is

bytes has a
__contains__ method, memoryview doesn't and so the in operator ends up iterating through memoryview and doing literal comparisons.
@ignaloidas yeah. but why doesn't it have that ;w;
@whitequark because memory view is for a whole bunch of things that aren't bytestrings and as such can't have nice things...

relatedly, the problems with it's index method:
https://discuss.python.org/t/memoryview-index-860x-slower-than-bytes-index/104973/3
Memoryview.index() 860x slower than bytes.index()

Sometimes profile results can be surprising but looking at the code the orders of magnitude timing difference is hardly surprising. It turns every byte one-by-one into a heap-allocated Python object just to then compare it with another Python object and deallocate. If you wanted to make this faster you would convert the input to a C type at the start and then do all the comparisons with C types. That would not be difficult but just needs more code to handle the different possible input types an...

Discussions on Python.org
@ignaloidas yeah, this... makes sense unfortunately