Skip to content

Documentation for object.__getitem__ is over-specified. #113313

Description

@rodrigogiraoserrao

Bug report

Bug description:

collections.deque is a sequence but doesn't implement the full sequence protocol (doesn't support slices).

collections.deque is a sequence:

from collections import deque
from collections.abc import Sequence
assert issubclass(deque, Sequence)  # No AssertionError

The docs on collections.abc.Sequence say this is an ABC for sequences, linking to the docs glossary entry on sequences:

ABCs for read-only and mutable sequences.

In turn, the glossary entry says sequences must implement __getitem__:

An iterable which supports efficient element access using integer indices via the __getitem__() special method [...]

Finally, the __getitem__ docs say that sequences must accept integers and slice objects:

[...] For sequence types, the accepted keys should be integers and slice objects.[...]

(Excerpts taken from the Python 3.12.1 documentation on 20/12/2023.)

I see one of three resolutions:

  1. issubclass(deque, Sequence) returns False
  2. we implement slicing for deque
  3. change the docs on __getitem__ to say “For sequence types, the accepted keys should be integers (and optionally slice objects).”

I don't know which one is the “best”.

CPython versions tested on:

3.8, 3.12

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions