You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]], /)?
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.
This is valid also for str/bytes. For some reasons (perhaps, leaking of the sys.maxsize value as a default for stop parameter) signatures were overriden here:
>>> inspect.signature(str.index)
Traceback (most recent call last):
[...]
ValueError: <method 'index' of 'str' objects> builtin has invalid signature
I think this should be fixed.
The documentation, probably, could be fixed by using multiple signatures:
Hi @skirpichev, I'd like to take this on as my first contribution to CPython. I will draft a PR to replace the old bracket syntax with the two explicit signatures using the positional-only / marker exactly as you suggested.
Activity
skirpichev commentedon Jun 24, 2026
In all cases signatures could be represented in a valid Python syntax:
This is valid also for str/bytes. For some reasons (perhaps, leaking of the sys.maxsize value as a default for stop parameter) signatures were overriden here:
>>> inspect.signature(str.index) Traceback (most recent call last): [...] ValueError: <method 'index' of 'str' objects> builtin has invalid signatureI think this should be fixed.
The documentation, probably, could be fixed by using multiple signatures:
It's undocumented syntax, unfortunately. See e.g. https://discuss.python.org/t/95015/
subscapularis commentedon Jun 24, 2026
Hi @skirpichev, I'd like to take this on as my first contribution to CPython. I will draft a PR to replace the old bracket syntax with the two explicit signatures using the positional-only / marker exactly as you suggested.
pythongh-152030: Clarify sequence.index() signature