Skip to content

Commit

Permalink
update get_a1_from_absolute_range to work with None
Browse files Browse the repository at this point in the history
  • Loading branch information
alifeee committed Oct 25, 2023
1 parent b1e9aab commit 0e698de
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gspread/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from functools import wraps
from itertools import chain
from math import inf
from typing import Mapping
from typing import Mapping, Optional
from urllib.parse import quote as uquote

from google.auth.credentials import Credentials as Credentials
Expand Down Expand Up @@ -910,17 +910,20 @@ def is_full_a1_notation(range_name: str) -> bool:
return A1_ADDR_FULL_RE.search(range_name) is not None


def get_a1_from_absolute_range(range_name: str) -> str:
def get_a1_from_absolute_range(range_name: Optional[str]) -> str:
"""Get the A1 notation from an absolute range name.
"Sheet1!A1:B2" -> "A1:B2"
"A1:B2" -> "A1:B2"
None -> ""
Args:
range_name (str): The range name to check.
range_name (str | None): The range name to check.
Returns:
str: The A1 notation of the range name stripped of the sheet.
"""
if range_name is None:
return ""
if "!" in range_name:
return range_name.split("!")[1]
return range_name
Expand Down

0 comments on commit 0e698de

Please sign in to comment.