|  | 
| 20 | 20 |     TYPE_CHECKING, | 
| 21 | 21 |     Any, | 
| 22 | 22 |     Callable, | 
|  | 23 | +    Dict, | 
| 23 | 24 |     Generic, | 
| 24 | 25 |     Iterator, | 
| 25 | 26 |     Literal, | 
| 26 | 27 |     NamedTuple, | 
| 27 | 28 |     NoReturn, | 
| 28 | 29 |     Sequence, | 
|  | 30 | +    Tuple, | 
| 29 | 31 |     TypeVar, | 
|  | 32 | +    Union, | 
| 30 | 33 |     overload, | 
| 31 | 34 | ) | 
| 32 | 35 | 
 | 
|  | 
| 88 | 91 |     from .result_batch import ResultBatch | 
| 89 | 92 | 
 | 
| 90 | 93 | 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]]) | 
| 92 | 95 | 
 | 
| 93 | 96 | logger = getLogger(__name__) | 
| 94 | 97 | 
 | 
| @@ -426,6 +429,10 @@ def __del__(self) -> None:  # pragma: no cover | 
| 426 | 429 |             if logger.getEffectiveLevel() <= logging.INFO: | 
| 427 | 430 |                 logger.info(e) | 
| 428 | 431 | 
 | 
|  | 432 | +    @property | 
|  | 433 | +    @abc.abstractmethod | 
|  | 434 | +    def _use_dict_result(self) -> bool: ... | 
|  | 435 | + | 
| 429 | 436 |     @property | 
| 430 | 437 |     def description(self) -> list[ResultMetadata]: | 
| 431 | 438 |         if self._description is None: | 
| @@ -1936,26 +1943,28 @@ class SnowflakeCursor(SnowflakeCursorBase[tuple[Any, ...]]): | 
| 1936 | 1943 |         is_file_transfer: Whether, or not the current command is a put, or get. | 
| 1937 | 1944 |     """ | 
| 1938 | 1945 | 
 | 
| 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 | 
| 1942 | 1949 | 
 | 
| 1943 | 1950 |     def fetchone(self) -> tuple[Any, ...] | None: | 
| 1944 | 1951 |         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}") | 
| 1946 | 1954 |         return row | 
| 1947 | 1955 | 
 | 
| 1948 | 1956 | 
 | 
| 1949 | 1957 | class DictCursor(SnowflakeCursorBase[dict[str, Any]]): | 
| 1950 | 1958 |     """Cursor returning results in a dictionary.""" | 
| 1951 | 1959 | 
 | 
| 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 | 
| 1955 | 1963 | 
 | 
| 1956 | 1964 |     def fetchone(self) -> dict[str, Any] | None: | 
| 1957 | 1965 |         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}") | 
| 1959 | 1968 |         return row | 
| 1960 | 1969 | 
 | 
| 1961 | 1970 | 
 | 
|  | 
0 commit comments