Issue 41285: memoryview does not support subclassing
Created on 2020-07-12 14:23 by mdehoon, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Messages (6) | |||
|---|---|---|---|
| msg373554 - (view) | Author: Michiel de Hoon (mdehoon) * | Date: 2020-07-12 14:23 | |
Currently memoryview does not support subclassing:
>>> class B(memoryview): pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: type 'memoryview' is not an acceptable base type
Subclassing memoryview can be useful when
- class A supports the buffer protocol;
- class B wraps class A and should support the buffer protocol provided by class A;
- class A does not support subclassing.
In this situation,
class B(memoryview):
def __new__(cls, a):
return super(B, cls).__new__(cls, a)
where a is an instance of class A, would let instances of B support the buffer protocol provided by a.
Is there any particular reason why memoryview does not support subclassing?
|
|||
| msg373601 - (view) | Author: Inada Naoki (methane) * ![]() |
Date: 2020-07-13 12:56 | |
Would you be more specific about why you need that feature on the Python-ideas mailing list or "Ideas" category on discuss.python.org? |
|||
| msg373668 - (view) | Author: Michiel de Hoon (mdehoon) * | Date: 2020-07-15 06:39 | |
Thank you, I have posted an explanation in the "Ideas" category of discuss.python.org. |
|||
| msg373693 - (view) | Author: Stefan Krah (skrah) * ![]() |
Date: 2020-07-15 13:26 | |
If I understand this correctly, I think this may be a duplicate of #13797. Something like a __getbuffer__ protocol would be needed. I'm not saying we *should* go that route, just stating the requirements from my perspective. |
|||
| msg373697 - (view) | Author: Michiel de Hoon (mdehoon) * | Date: 2020-07-15 14:13 | |
You are correct, this is indeed a duplicate of #13797. My apologies for not finding this issue before opening a new one. If there are no objections, I will close this issue as a duplicate. |
|||
| msg373705 - (view) | Author: Stefan Krah (skrah) * ![]() |
Date: 2020-07-15 17:36 | |
Yes, let's make #13797 a superseder. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:33 | admin | set | github: 85457 |
| 2020-07-15 17:38:42 | skrah | set | status: open -> closed superseder: Allow objects implemented in pure Python to export PEP 3118 buffers resolution: duplicate stage: resolved |
| 2020-07-15 17:36:54 | skrah | set | messages: + msg373705 |
| 2020-07-15 14:13:53 | mdehoon | set | messages: + msg373697 |
| 2020-07-15 13:26:51 | skrah | set | messages: + msg373693 |
| 2020-07-15 06:39:52 | mdehoon | set | messages: + msg373668 |
| 2020-07-13 12:56:04 | methane | set | nosy:
+ methane messages: + msg373601 |
| 2020-07-12 16:08:26 | christian.heimes | set | versions: - Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9 |
| 2020-07-12 14:37:24 | xtreak | set | nosy:
+ skrah |
| 2020-07-12 14:23:24 | mdehoon | create | |
