Skip to content
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

Improve Worksheet.sort() signature #1342

Merged
merged 1 commit into from
Nov 1, 2023
Merged
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
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