|  | 
| 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: | 
| @@ -1936,26 +1941,28 @@ class SnowflakeCursor(SnowflakeCursorBase[tuple[Any, ...]]): | 
| 1936 | 1941 |         is_file_transfer: Whether, or not the current command is a put, or get. | 
| 1937 | 1942 |     """ | 
| 1938 | 1943 | 
 | 
| 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 | 
| 1942 | 1947 | 
 | 
| 1943 | 1948 |     def fetchone(self) -> tuple[Any, ...] | None: | 
| 1944 | 1949 |         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}") | 
| 1946 | 1952 |         return row | 
| 1947 | 1953 | 
 | 
| 1948 | 1954 | 
 | 
| 1949 | 1955 | class DictCursor(SnowflakeCursorBase[dict[str, Any]]): | 
| 1950 | 1956 |     """Cursor returning results in a dictionary.""" | 
| 1951 | 1957 | 
 | 
| 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 | 
| 1955 | 1961 | 
 | 
| 1956 | 1962 |     def fetchone(self) -> dict[str, Any] | None: | 
| 1957 | 1963 |         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}") | 
| 1959 | 1966 |         return row | 
| 1960 | 1967 | 
 | 
| 1961 | 1968 | 
 | 
|  | 
0 commit comments