Skip to content

Commit

Permalink
Improve Worksheet.sort() signature
Browse files Browse the repository at this point in the history
Instead of using generic `kwargs`
Mention the argument `range` explicitly and add it's type.

Signed-off-by: Alexandre Lavigne <[email protected]>
  • Loading branch information
lavigne958 committed Nov 1, 2023
1 parent d0a0b48 commit 0cb61b6
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions gspread/worksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Iterable,
Iterator,
List,
Literal,
Mapping,
MutableMapping,
Optional,
Expand Down Expand Up @@ -1580,9 +1581,9 @@ def resize(
self._properties["gridProperties"]["columnCount"] = cols
return res

# TODO(post Python 2): replace the method signature with
# def sort(self, *specs, range=None):
def sort(self, *specs: Tuple[int, str], **kwargs) -> JSONResponse:
def sort(
self, *specs: Tuple[int, Literal["asc", "des"]], range: Optional[str] = None
) -> JSONResponse:
"""Sorts worksheet using given sort orders.
:param list specs: The sort order per column. Each sort order
Expand All @@ -1600,16 +1601,10 @@ def sort(self, *specs: Tuple[int, str], **kwargs) -> JSONResponse:
# and column 'B' Z -> A
wks.sort((7, 'asc'), (2, 'des'), range='A2:G8')
Warning::
This function signature will change, arguments will swap places: sort(range, specs)
.. versionadded:: 3.4
"""
range_name = kwargs.pop("range", None)

if range_name:
start_a1, end_a1 = range_name.split(":")
if range:
start_a1, end_a1 = range.split(":")
start_row, start_col = a1_to_rowcol(start_a1)
end_row, end_col = a1_to_rowcol(end_a1)
else:
Expand Down

0 comments on commit 0cb61b6

Please sign in to comment.