Skip to content

Commit 80253de

Browse files
committed
Address feedback
1 parent 840ecc7 commit 80253de

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/snowflake/connector/cursor.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
NoReturn,
2828
Sequence,
2929
TypeVar,
30+
Union,
3031
overload,
3132
)
3233

@@ -88,7 +89,7 @@
8889
from .result_batch import ResultBatch
8990

9091
T = TypeVar("T", bound=collections.abc.Sequence)
91-
FetchRow = TypeVar("FetchRow", bound=tuple[Any, ...] | dict[str, Any])
92+
FetchRow = TypeVar("FetchRow", bound=Union[tuple[Any, ...], dict[str, Any]])
9293

9394
logger = getLogger(__name__)
9495

@@ -426,6 +427,10 @@ def __del__(self) -> None: # pragma: no cover
426427
if logger.getEffectiveLevel() <= logging.INFO:
427428
logger.info(e)
428429

430+
@property
431+
@abc.abstractmethod
432+
def _use_dict_result(self) -> bool: ...
433+
429434
@property
430435
def description(self) -> list[ResultMetadata]:
431436
if self._description is None:
@@ -1936,26 +1941,28 @@ class SnowflakeCursor(SnowflakeCursorBase[tuple[Any, ...]]):
19361941
is_file_transfer: Whether, or not the current command is a put, or get.
19371942
"""
19381943

1939-
def __init__(self, *args, **kwargs):
1940-
super().__init__(*args, **kwargs)
1941-
self._use_dict_result = False
1944+
@property
1945+
def _use_dict_result(self) -> bool:
1946+
return False
19421947

19431948
def fetchone(self) -> tuple[Any, ...] | None:
19441949
row = self._fetchone()
1945-
assert row is None or isinstance(row, tuple)
1950+
if not (row is None or isinstance(row, tuple)):
1951+
raise TypeError(f"fetchone got unexpected result: {row}")
19461952
return row
19471953

19481954

19491955
class DictCursor(SnowflakeCursorBase[dict[str, Any]]):
19501956
"""Cursor returning results in a dictionary."""
19511957

1952-
def __init__(self, *args, **kwargs):
1953-
super().__init__(*args, **kwargs)
1954-
self._use_dict_result = True
1958+
@property
1959+
def _use_dict_result(self) -> bool:
1960+
return True
19551961

19561962
def fetchone(self) -> dict[str, Any] | None:
19571963
row = self._fetchone()
1958-
assert row is None or isinstance(row, dict)
1964+
if not (row is None or isinstance(row, dict)):
1965+
raise TypeError(f"fetchone got unexpected result: {row}")
19591966
return row
19601967

19611968

test/unit/test_cursor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def mock_is_closed(*args, **kwargs):
7878
cursor.execute("", _dataframe_ast="ABCD")
7979

8080

81-
@patch("snowflake.connector.cursor.SnowflakeCursor._SnowflakeCursor__cancel_query")
81+
@patch("snowflake.connector.cursor.SnowflakeCursor._SnowflakeCursorBase__cancel_query")
8282
def test_cursor_execute_timeout(mockCancelQuery):
8383
def mock_cmd_query(*args, **kwargs):
8484
time.sleep(10)

0 commit comments

Comments
 (0)