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

Fixup get empty cell value is None #1404

Merged
merged 1 commit into from
Feb 4, 2024
Merged
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
4 changes: 2 additions & 2 deletions gspread/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class Cell:
in a :class:`~gspread.worksheet.Worksheet`.
"""

def __init__(self, row: int, col: int, value: str = "") -> None:
def __init__(self, row: int, col: int, value: Optional[str] = "") -> None:
self._row: int = row
self._col: int = col

#: Value of the cell.
self.value: str = value
self.value: Optional[str] = value

@classmethod
def from_address(cls, label: str, value: str = "") -> "Cell":
Expand Down
2 changes: 1 addition & 1 deletion gspread/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def cell_list_to_rect(cell_list: List["Cell"]) -> List[List[Optional[str]]]:
if not cell_list:
return []

rows: Dict[int, Dict[int, str]] = defaultdict(dict)
rows: Dict[int, Dict[int, Optional[str]]] = defaultdict(dict)

row_offset = min(c.row for c in cell_list)
col_offset = min(c.col for c in cell_list)
Expand Down
14 changes: 9 additions & 5 deletions gspread/worksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,14 @@ def cell(
value_render_option=value_render_option,
return_type=GridRangeType.ValueRange,
)
try:
value = str(data[0][0])
except IndexError:
value = str(None)

# we force a return type to GridRangeType.ValueRange
# help typing tool to see it too :-)
if isinstance(data, ValueRange):
value = data.first()
else:
raise RuntimeError("returned data must be of type ValueRange")
alifeee marked this conversation as resolved.
Show resolved Hide resolved

except KeyError:
value = ""

Expand Down Expand Up @@ -2209,7 +2213,7 @@ def _finder(
str_query = query

def match(x: Cell) -> bool:
if case_sensitive:
if case_sensitive or x.value is None:
lavigne958 marked this conversation as resolved.
Show resolved Hide resolved
return x.value == str_query
else:
return x.value.casefold() == str_query.casefold()
Expand Down
Loading