Skip to content

Specify that dunder get/set item accepts SupportsIndex #383

@honno

Description

@honno

Currently __getitem__()/__setitem__() accept array as keys, which implicitly has to be boolean arrays, or 0d integer arrays i.e. has a working __index__(). The latter is not an obvious concept to grasp, and maybe not even quite specified anyway.

I propose we add the stdlib typing.SupportsIndex to the get/set item signatures, specifically before array. This does add support for any indexable type, but that seems okay, and was the intention anyway when __index__() was proposed in #231. I also think a note would be helpful in regards to what arrays are accepted, e.g.:

key can only be an array if it is valid for boolean array indexing, or supports __index__() i.e. is a 0-dimensional integer array.

cc @kgryte @asmeurer

Metadata

Metadata

Assignees

No one assigned

    Labels

    MaintenanceBug fix, typo fix, or general maintenance.topic: IndexingArray indexing.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy