|  | 
| 27 | 27 |     NoReturn, | 
| 28 | 28 |     Sequence, | 
| 29 | 29 |     TypeVar, | 
|  | 30 | +    Union, | 
| 30 | 31 |     overload, | 
| 31 | 32 | ) | 
| 32 | 33 | 
 | 
|  | 
| 88 | 89 |     from .result_batch import ResultBatch | 
| 89 | 90 | 
 | 
| 90 | 91 | 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]]) | 
| 92 | 93 | 
 | 
| 93 | 94 | logger = getLogger(__name__) | 
| 94 | 95 | 
 | 
| @@ -426,6 +427,10 @@ def __del__(self) -> None:  # pragma: no cover | 
| 426 | 427 |             if logger.getEffectiveLevel() <= logging.INFO: | 
| 427 | 428 |                 logger.info(e) | 
| 428 | 429 | 
 | 
|  | 430 | +    @property | 
|  | 431 | +    @abc.abstractmethod | 
|  | 432 | +    def _use_dict_result(self) -> bool: ... | 
|  | 433 | + | 
| 429 | 434 |     @property | 
| 430 | 435 |     def description(self) -> list[ResultMetadata]: | 
| 431 | 436 |         if self._description is None: | 
| @@ -1931,26 +1936,28 @@ class SnowflakeCursor(SnowflakeCursorBase[tuple[Any, ...]]): | 
| 1931 | 1936 |         is_file_transfer: Whether, or not the current command is a put, or get. | 
| 1932 | 1937 |     """ | 
| 1933 | 1938 | 
 | 
| 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 | 
| 1937 | 1942 | 
 | 
| 1938 | 1943 |     def fetchone(self) -> tuple[Any, ...] | None: | 
| 1939 | 1944 |         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}") | 
| 1941 | 1947 |         return row | 
| 1942 | 1948 | 
 | 
| 1943 | 1949 | 
 | 
| 1944 | 1950 | class DictCursor(SnowflakeCursorBase[dict[str, Any]]): | 
| 1945 | 1951 |     """Cursor returning results in a dictionary.""" | 
| 1946 | 1952 | 
 | 
| 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 | 
| 1950 | 1956 | 
 | 
| 1951 | 1957 |     def fetchone(self) -> dict[str, Any] | None: | 
| 1952 | 1958 |         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}") | 
| 1954 | 1961 |         return row | 
| 1955 | 1962 | 
 | 
| 1956 | 1963 | 
 | 
|  | 
0 commit comments