Skip to content

Commit ac6f96b

Browse files
committed
Address feedback
1 parent 888ce70 commit ac6f96b

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:
@@ -1931,26 +1936,28 @@ class SnowflakeCursor(SnowflakeCursorBase[tuple[Any, ...]]):
19311936
is_file_transfer: Whether, or not the current command is a put, or get.
19321937
"""
19331938

1934-
def __init__(self, *args, **kwargs):
1935-
super().__init__(*args, **kwargs)
1936-
self._use_dict_result = False
1939+
@property
1940+
def _use_dict_result(self) -> bool:
1941+
return False
19371942

19381943
def fetchone(self) -> tuple[Any, ...] | None:
19391944
row = self._fetchone()
1940-
assert row is None or isinstance(row, tuple)
1945+
if not (row is None or isinstance(row, tuple)):
1946+
raise TypeError(f"fetchone got unexpected result: {row}")
19411947
return row
19421948

19431949

19441950
class DictCursor(SnowflakeCursorBase[dict[str, Any]]):
19451951
"""Cursor returning results in a dictionary."""
19461952

1947-
def __init__(self, *args, **kwargs):
1948-
super().__init__(*args, **kwargs)
1949-
self._use_dict_result = True
1953+
@property
1954+
def _use_dict_result(self) -> bool:
1955+
return True
19501956

19511957
def fetchone(self) -> dict[str, Any] | None:
19521958
row = self._fetchone()
1953-
assert row is None or isinstance(row, dict)
1959+
if not (row is None or isinstance(row, dict)):
1960+
raise TypeError(f"fetchone got unexpected result: {row}")
19541961
return row
19551962

19561963

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)