Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Description
Bug report
Bug description:
Thememoryview builtin is registered as aSequence, but doesn't implement the full API, because it doesn't inherit fromSequence at runtime and doesn't implement the mixin methods.
>>>importcollections.abc>>>issubclass(memoryview,collections.abc.Sequence)True>>>collections.abc.Sequence.index<functionSequence.indexat0x10148d250>>>>memoryview.indexTraceback (mostrecentcalllast):File"<python-input-4>",line1,in<module>memoryview.indexAttributeError: typeobject'memoryview'hasnoattribute'index'
Among the methods listed for Sequence inthe documentation, memoryview is missing__contains__,__reversed__,index, andcount. This is causing problems for typing; in the typeshed stubs we have to either lie one way by claiming that memoryview has methods it doesn't have, or lie another way by claiming it is not a Sequence whenissubclass() says otherwise at runtime (python/typeshed#12800). To fix this, we should either make memoryview not a Sequence, or add the missing methods. The former has compatibility implications, so I propose to add the methods in 3.14.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-125420: implement
Sequence.countAPI onmemoryviewobjects #125443 - gh-125420: implement
Sequence.indexAPI onmemoryviewobjects #125446 - (under consideration)gh-125420: implement
Sequence.__contains__API onmemoryviewobjects #125441 - (under consideration)gh-125420: implement
Sequence.__reversed__API onmemoryviewobjects #125505