Skip to content

Commit 291189a

Browse files
Typecheck cursor.py
1 parent 96d8944 commit 291189a

File tree

5 files changed

+139
-118
lines changed

5 files changed

+139
-118
lines changed

.pre-commit-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ repos:
9494
(?x)^src/snowflake/connector/(
9595
constants
9696
| compat
97+
| cursor
9798
| dbapi
9899
| description
99100
| errorcode

src/snowflake/connector/connection.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@
2525
from threading import Lock
2626
from time import strptime
2727
from types import TracebackType
28-
from typing import Any, Callable, Generator, Iterable, Iterator, NamedTuple, Sequence, TypeVar
28+
from typing import (
29+
Any,
30+
Callable,
31+
Generator,
32+
Iterable,
33+
Iterator,
34+
NamedTuple,
35+
Sequence,
36+
TypeVar,
37+
)
2938
from uuid import UUID
3039

3140
from cryptography.hazmat.backends import default_backend
@@ -115,7 +124,7 @@
115124
DEFAULT_CLIENT_PREFETCH_THREADS = 4
116125
MAX_CLIENT_PREFETCH_THREADS = 10
117126
DEFAULT_BACKOFF_POLICY = exponential_backoff()
118-
T = TypeVar('T', bound=SnowflakeCursor)
127+
T = TypeVar("T", bound=SnowflakeCursor)
119128

120129

121130
def DefaultConverterClass() -> type:
@@ -443,7 +452,7 @@ def __init__(
443452
elif "streamlit" in sys.modules:
444453
kwargs["application"] = "streamlit"
445454

446-
self.converter = None
455+
self.converter: SnowflakeConverter | None = None
447456
self.query_context_cache: QueryContextCache | None = None
448457
self.query_context_cache_size = 5
449458
if connections_file_path is not None:
@@ -869,9 +878,7 @@ def rollback(self) -> None:
869878
"""Rolls back the current transaction."""
870879
self.cursor().execute("ROLLBACK")
871880

872-
def cursor(
873-
self, cursor_class: type[T] = SnowflakeCursor
874-
) -> T:
881+
def cursor(self, cursor_class: type[T] = SnowflakeCursor) -> T:
875882
"""Creates a cursor object. Each statement will be executed in a new cursor object."""
876883
logger.debug("cursor")
877884
if not self.rest:
@@ -939,7 +946,7 @@ def setup_ocsp_privatelink(app, hostname) -> None:
939946

940947
def __open_connection(self):
941948
"""Opens a new network connection."""
942-
self.converter = self._converter_class(
949+
self.converter = self.converter_class(
943950
use_numpy=self._numpy, support_negative_year=self._support_negative_year
944951
)
945952

0 commit comments

Comments
 (0)