Skip to content

Commit 20d53ad

Browse files
Add docstrings for referenced list methods
1 parent f8112e4 commit 20d53ad

File tree

1 file changed

+78
-11
lines changed

1 file changed

+78
-11
lines changed

lang/en/typeshed/stdlib/builtins.pyi

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -716,26 +716,93 @@ class list(MutableSequence[_T], Generic[_T]):
716716
def __init__(self) -> None: ...
717717
@overload
718718
def __init__(self, iterable: Iterable[_T]) -> None: ...
719-
def clear(self) -> None: ...
719+
def clear(self) -> None:
720+
"""Remove all items from the list.
721+
"""
722+
...
720723
def copy(self) -> list[_T]: ...
721-
def append(self, __object: _T) -> None: ...
724+
def append(self, __object: _T) -> None:
725+
"""Add an item to the end of the list.
726+
727+
Example: ``[1, 2, 3].append(4)``
728+
729+
:param __object: An item to add the end of the list.
730+
"""
731+
...
722732
def extend(self, __iterable: Iterable[_T]) -> None: ...
723-
def pop(self, __index: SupportsIndex = ...) -> _T: ...
733+
def pop(self, __index: SupportsIndex = ...) -> _T:
734+
"""Remove and return an item from the list.
735+
736+
If no ``index`` is provided, the last item in the list is removed.
737+
An ``IndexError`` is raised if the ``index`` is outside of the list range.
738+
739+
Example: ``[1, 2, 3, 4].pop()``
740+
741+
:param __index: The index of the item to remove.
742+
:return: An item from the list.
743+
"""
744+
...
724745
def index(
725746
self, __value: _T, __start: SupportsIndex = ..., __stop: SupportsIndex = ...
726747
) -> int: ...
727-
def count(self, __value: _T) -> int: ...
728-
def insert(self, __index: SupportsIndex, __object: _T) -> None: ...
729-
def remove(self, __value: _T) -> None: ...
730-
def reverse(self) -> None: ...
748+
def count(self, __value: _T) -> int:
749+
"""Get the number of times an item appears in the list.
750+
751+
Example: ``["a", "b", "a"].count("a")``
752+
753+
:param __value: The item to count.
754+
:return: The number of times an item appears in the list.
755+
"""
756+
...
757+
def insert(self, __index: SupportsIndex, __object: _T) -> None:
758+
"""Insert an item into the list at a given position.
759+
760+
Example: ``["a", "b", "a"].insert(2, "c")``
761+
762+
:param __index: The position at which to insert the item.
763+
:param __object: The item to insert.
764+
"""
765+
...
766+
def remove(self, __value: _T) -> None:
767+
"""Remove the first occurence of a value from the list.
768+
769+
A ``ValueError`` is raised if the ``value`` does not appear in the list.
770+
771+
Example: ``["a", "b", "a"].remove("a")``
772+
773+
:param __value: The item to remove.
774+
"""
775+
...
776+
def reverse(self) -> None:
777+
"""Reverses the order of the items in the list, in place.
778+
779+
Example: ``[3, 2, 1].reverse()`
780+
"""
781+
...
731782
@overload
732783
def sort(
733-
self: list[SupportsLessThanT], *, key: None = ..., reverse: bool = ...
734-
) -> None: ...
784+
self: list[SupportsLessThanT], *, key: None = None, reverse: bool = False
785+
) -> None:
786+
"""Sorts the items in the list, in place.
787+
788+
Example: ``[1, 3, 2].sort()`
789+
790+
:param key: A function used to specify the comparison between items in the list.
791+
:param reverse: A ``bool`` used to reverse the sorting order.
792+
"""
793+
...
735794
@overload
736795
def sort(
737-
self, *, key: Callable[[_T], SupportsLessThan], reverse: bool = ...
738-
) -> None: ...
796+
self, *, key: Callable[[_T], SupportsLessThan], reverse: bool = False
797+
) -> None:
798+
"""Sorts the items in the list, in place.
799+
800+
Example: ``['Watermelon', 'avocado'].sort(str.lower)``
801+
802+
:param key: A function used to specify the comparison between items in the list.
803+
:param reverse: A ``bool`` used to reverse the sorting order.
804+
"""
805+
...
739806
def __len__(self) -> int: ...
740807
def __iter__(self) -> Iterator[_T]: ...
741808
def __str__(self) -> str: ...

0 commit comments

Comments
 (0)