Skip to content

The data model and built-in types references disagree regarding sort() #138562

@AA-Turner

Description

@AA-Turner

Documentation

The data model and built-in types reference are inconsistent regarding whether sort() should be an expected mutable sequence method. This was noted by @serhiy-storchaka during review of #138474.

The data model, in 'Emulating container types' states:

Mutable sequences should provide methods [...] and sort(), like Python standard list objects.

The built-in types reference, in 'Mutable Sequence Types' stated1:

The operations in the following table are defined on mutable sequence types

with sort() not included. Indeed, in stdtypes.rst, list.sort() is documented as an 'additional method', beyond the mutable sequence interface.


Relevant history:

  • sort() was added to the datamodel in 83b2f8a (23/7/1998), and with the text effectively unchanged since.
  • sort() was removed from the table in stdtypes.rst in 273069c (20/8/2012).
  • A note that bytes (now bytearray) objects do not support sort() was added to the table in 226878c (31/8/2007). Before this, support for sort() was unqualified in stdtypes.rst.

Of the standard library sequence types, the only ones that implement a sort() method are list, collections.UserList, and multiprocessing.managers.BaseListProxy.

Given all of this, I propose that we update the data model to remove the reference to sort() as an expected sequence method. I think that this is the most pragmatic solution.

Linked PRs

Footnotes

  1. before the recent PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions