Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine types and enable typechecking in cursor.py #2145

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ repos:
(?x)^src/snowflake/connector/(
constants
| compat
| cursor
| dbapi
| description
| errorcode
Expand Down
6 changes: 4 additions & 2 deletions DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne

# Release Notes

- v3.12.5(TBD)
- v3.13.1(January 23,2025)
- Updated type hints for cursor object

- v3.13.0(January 23,2025)
- Added a feature to limit the sizes of IO-bound ThreadPoolExecutors during PUT and GET commands.
- Adding support for the new PAT authentication method.
- Updated README.md to include instructions on how to verify package signatures using `cosign`.
- Updated the log level for cursor's chunk rowcount from INFO to DEBUG.
- Added a feature to verify if the connection is still good enough to send queries over.
Expand Down
20 changes: 14 additions & 6 deletions src/snowflake/connector/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@
from threading import Lock
from time import strptime
from types import TracebackType
from typing import Any, Callable, Generator, Iterable, Iterator, NamedTuple, Sequence
from typing import (
Any,
Callable,
Generator,
Iterable,
Iterator,
NamedTuple,
Sequence,
TypeVar,
)
from uuid import UUID

from cryptography.hazmat.backends import default_backend
Expand Down Expand Up @@ -115,6 +124,7 @@
DEFAULT_CLIENT_PREFETCH_THREADS = 4
MAX_CLIENT_PREFETCH_THREADS = 10
DEFAULT_BACKOFF_POLICY = exponential_backoff()
T = TypeVar("T", bound=SnowflakeCursor)


def DefaultConverterClass() -> type:
Expand Down Expand Up @@ -442,7 +452,7 @@ def __init__(
elif "streamlit" in sys.modules:
kwargs["application"] = "streamlit"

self.converter = None
self.converter: SnowflakeConverter | None = None
self.query_context_cache: QueryContextCache | None = None
self.query_context_cache_size = 5
if connections_file_path is not None:
Expand Down Expand Up @@ -868,9 +878,7 @@ def rollback(self) -> None:
"""Rolls back the current transaction."""
self.cursor().execute("ROLLBACK")

def cursor(
self, cursor_class: type[SnowflakeCursor] = SnowflakeCursor
) -> SnowflakeCursor:
def cursor(self, cursor_class: type[T] = SnowflakeCursor) -> T:
"""Creates a cursor object. Each statement will be executed in a new cursor object."""
logger.debug("cursor")
if not self.rest:
Expand Down Expand Up @@ -938,7 +946,7 @@ def setup_ocsp_privatelink(app, hostname) -> None:

def __open_connection(self):
"""Opens a new network connection."""
self.converter = self._converter_class(
self.converter = self.converter_class(
use_numpy=self._numpy, support_negative_year=self._support_negative_year
)

Expand Down
Loading
Loading