Skip to content

Commit 09d228b

Browse files
committed
Address feedback
1 parent 840ecc7 commit 09d228b

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/snowflake/connector/cursor.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@
2020
TYPE_CHECKING,
2121
Any,
2222
Callable,
23+
Dict,
2324
Generic,
2425
Iterator,
2526
Literal,
2627
NamedTuple,
2728
NoReturn,
2829
Sequence,
30+
Tuple,
2931
TypeVar,
32+
Union,
3033
overload,
3134
)
3235

@@ -88,7 +91,7 @@
8891
from .result_batch import ResultBatch
8992

9093
T = TypeVar("T", bound=collections.abc.Sequence)
91-
FetchRow = TypeVar("FetchRow", bound=tuple[Any, ...] | dict[str, Any])
94+
FetchRow = TypeVar("FetchRow", bound=Union[Tuple[Any, ...], Dict[str, Any]])
9295

9396
logger = getLogger(__name__)
9497

@@ -426,6 +429,10 @@ def __del__(self) -> None: # pragma: no cover
426429
if logger.getEffectiveLevel() <= logging.INFO:
427430
logger.info(e)
428431

432+
@property
433+
@abc.abstractmethod
434+
def _use_dict_result(self) -> bool: ...
435+
429436
@property
430437
def description(self) -> list[ResultMetadata]:
431438
if self._description is None:
@@ -1936,26 +1943,28 @@ class SnowflakeCursor(SnowflakeCursorBase[tuple[Any, ...]]):
19361943
is_file_transfer: Whether, or not the current command is a put, or get.
19371944
"""
19381945

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

19431950
def fetchone(self) -> tuple[Any, ...] | None:
19441951
row = self._fetchone()
1945-
assert row is None or isinstance(row, tuple)
1952+
if not (row is None or isinstance(row, tuple)):
1953+
raise TypeError(f"fetchone got unexpected result: {row}")
19461954
return row
19471955

19481956

19491957
class DictCursor(SnowflakeCursorBase[dict[str, Any]]):
19501958
"""Cursor returning results in a dictionary."""
19511959

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

19561964
def fetchone(self) -> dict[str, Any] | None:
19571965
row = self._fetchone()
1958-
assert row is None or isinstance(row, dict)
1966+
if not (row is None or isinstance(row, dict)):
1967+
raise TypeError(f"fetchone got unexpected result: {row}")
19591968
return row
19601969

19611970

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)