Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memoryview does not support subclassing #85457

Closed
mdehoon mannequin opened this issue Jul 12, 2020 · 6 comments
Closed

memoryview does not support subclassing #85457

mdehoon mannequin opened this issue Jul 12, 2020 · 6 comments
Labels
3.10 only security fixes topic-C-API type-feature A feature request or enhancement

Comments

@mdehoon
Copy link
Mannequin

mdehoon mannequin commented Jul 12, 2020

BPO 41285
Nosy @methane, @skrah
Superseder
  • bpo-13797: Allow objects implemented in pure Python to export PEP 3118 buffers
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-07-15.17:38:42.139>
    created_at = <Date 2020-07-12.14:23:24.421>
    labels = ['expert-C-API', 'type-feature', '3.10']
    title = 'memoryview does not support subclassing'
    updated_at = <Date 2020-07-15.17:38:42.138>
    user = 'https://bugs.python.org/mdehoon'

    bugs.python.org fields:

    activity = <Date 2020-07-15.17:38:42.138>
    actor = 'skrah'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-07-15.17:38:42.139>
    closer = 'skrah'
    components = ['C API']
    creation = <Date 2020-07-12.14:23:24.421>
    creator = 'mdehoon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41285
    keywords = []
    message_count = 6.0
    messages = ['373554', '373601', '373668', '373693', '373697', '373705']
    nosy_count = 3.0
    nosy_names = ['mdehoon', 'methane', 'skrah']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '13797'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue41285'
    versions = ['Python 3.10']

    @mdehoon
    Copy link
    Mannequin Author

    mdehoon mannequin commented Jul 12, 2020

    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?

    @mdehoon mdehoon mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes topic-C-API type-feature A feature request or enhancement labels Jul 12, 2020
    @tiran tiran removed 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes labels Jul 12, 2020
    @methane
    Copy link
    Member

    methane commented Jul 13, 2020

    Would you be more specific about why you need that feature on the Python-ideas mailing list or "Ideas" category on discuss.python.org?

    @mdehoon
    Copy link
    Mannequin Author

    mdehoon mannequin commented Jul 15, 2020

    Thank you, I have posted an explanation in the "Ideas" category of discuss.python.org.

    @skrah
    Copy link
    Mannequin

    skrah mannequin commented Jul 15, 2020

    If I understand this correctly, I think this may be a duplicate of bpo-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.

    @mdehoon
    Copy link
    Mannequin Author

    mdehoon mannequin commented Jul 15, 2020

    You are correct, this is indeed a duplicate of bpo-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.

    @skrah
    Copy link
    Mannequin

    skrah mannequin commented Jul 15, 2020

    Yes, let's make bpo-13797 a superseder.

    @skrah skrah mannequin closed this as completed Jul 15, 2020
    @skrah skrah mannequin closed this as completed Jul 15, 2020
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes topic-C-API type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants