python / python/cpython

Clarification on signature for `index`

Open
#152,030 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs interpreter-core type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Documentation

The documentation reads that the signature for index (sequences, str, bytes) is .index(value[, start[, end]]), (the name of the first parameter changes depending on the underlying type). This leaves it open to interpretation whether any/all the parameters can be named parameters (that they cannot). Should the signature of these methods be .index(sub[, start[, end]], /)?

Ref: https://docs.python.org/3/library/stdtypes.html#sequence.index

Note: Tried looking whether there is some convention that specifies that if there are optional parameters in brackets, this means that the parameters are positional only, but was unable to find anything.

Linked PRs
  • gh-152092

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the sequence.index documentation at the referenced stdtypes.html section and review linked PR gh-152092 before making changes. Confirm how positional-only parameters are documented elsewhere, then ensure the index signatures clearly communicate the accepted calling form.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.