Skip to content

Clarify what memoryview is generic in #149488

Description

@jonathandung

Documentation

The current documentation page for memoryview includes a version-changed directive telling readers that the class started supporting subscripting in python 3.14. However, there is no mention as to what it is generic in. Maybe the answer was too obvious for the writer of the documentation, but it certainly isn't for a layman like me.

Activity

  1. sobolevn commented on May 7, 2026

    @sobolevn
    Member

    It is generic on the __getitem__ result:

    >>> memoryview(b'123')[0]
    49
    >>> memoryview(b'123').cast('c')[0]
    b'1'

    See https://github.com/python/typeshed/blob/d541d5a20cb7533c6eaba1430b5004f9b0e504ec/stdlib/builtins.pyi#L891

    We generally don't specify what the type is generic on, I am not sure that this is really needed? 🤔

  2. JelleZijlstra commented on May 7, 2026

    @JelleZijlstra
    Member

    We generally don't specify what the type is generic on, I am not sure that this is really needed?

    It ought to be documented somewhere. Currently when a type is generic, the only way to figure out what the generic parameter represents is to read the typeshed stubs. That's not something we should expect users to do.

    Documenting this in CPython is perhaps not ideal either, but I don't see a better place.

  3. ZeroIntensity commented on May 7, 2026

    @ZeroIntensity
    Member

    Maybe somewhere on typing.python.org?

  4. picnixz commented on May 7, 2026

    @picnixz
    Member

    I implemented the PEP-695 syntax in Sphinx because of Jelle wanted to document some generic classes (see sphinx-doc/sphinx#11438 and #104642) but not everything was included at that time (0511b6a). I think there was a discussion about adding the type parameters to the docs and we eventually decided not to. But I can't remember whether it was again decided differently or if we did something else

  5. jonathandung commented on May 24, 2026

    @jonathandung
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions