Skip to content

Allow item to be passed as a keyword argument to UserList.index() again #11600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions stdlib/collections/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,12 @@ class UserList(MutableSequence[_T]):
def copy(self) -> Self: ...
def __copy__(self) -> Self: ...
def count(self, item: _T) -> int: ...
# The runtime signature is "item, *args", and the arguments are then passed
# to `list.index`. In order to give more precise types, we pretend that the
# `item` argument is positional-only.
# All arguments are passed to `list.index` at runtime,
# *but* `item` can be passed as a keyword-only parameter in `UserList.index()`
# *if* neither `start` nor `stop` are provided
@overload
def index(self, *, item: _T) -> int: ...
@overload
def index(self, item: _T, start: SupportsIndex = 0, stop: SupportsIndex = sys.maxsize, /) -> int: ...
# All arguments are passed to `list.sort` at runtime, so the signature should be kept in line with `list.sort`.
@overload
Expand Down
1 change: 0 additions & 1 deletion tests/stubtest_allowlists/py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ asyncio.base_events.BaseEventLoop.subprocess_exec # BaseEventLoop adds several p
builtins.float.__setformat__ # Internal method for CPython test suite
builtins.property.__set_name__ # Doesn't actually exist
bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set
collections\.UserList\.index # ignoring pos-or-keyword parameter
configparser.ParsingError.filename
contextlib.AbstractAsyncContextManager.__class_getitem__
contextlib.AbstractContextManager.__class_getitem__
Expand Down
1 change: 0 additions & 1 deletion tests/stubtest_allowlists/py311.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ _csv.Writer
bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set
configparser.LegacyInterpolation.__init__
configparser.ParsingError.filename
collections\.UserList\.index # ignoring pos-or-keyword parameter
enum.Enum.__init__
enum.Enum._generate_next_value_
# Not strictly speaking a staticmethod on 3.11, but it acts like one:
Expand Down
1 change: 0 additions & 1 deletion tests/stubtest_allowlists/py312.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ _weakref.ProxyType.__reversed__ # Doesn't really exist
argparse._MutuallyExclusiveGroup.add_mutually_exclusive_group # deprecated, forwards arguments to super
ast.ImportFrom.level # None on the class, but never None on instances
builtins.property.__set_name__ # Doesn't actually exist
collections\.UserList\.index # ignoring pos-or-keyword parameter
dataclasses.KW_ONLY # white lies around defaults
enum.auto.__init__ # The stub for enum.auto is nothing like the implementation
enum.auto.value # The stub for enum.auto is nothing like the implementation
Expand Down
1 change: 1 addition & 0 deletions tests/stubtest_allowlists/py3_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ asyncio.Future.__init__ # Usually initialized from c object
asyncio.futures.Future.__init__ # Usually initialized from c object
builtins.dict.get
collections\.ChainMap\.fromkeys # https://github.com/python/mypy/issues/17023
collections\.UserList\.index # ignoring pos-or-keyword parameter
collections\.UserList\.sort # Runtime has *args but will error if any are supplied
configparser.SectionProxy.__getattr__ # SectionProxy can have arbitrary attributes when custom converters are used
# SectionProxy get functions are set in __init__
Expand Down