-
Notifications
You must be signed in to change notification settings - Fork 536
feat: Add types for snowflake.connector.connect
#2271
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
Open
max-muoto
wants to merge
6
commits into
snowflakedb:main
Choose a base branch
from
max-muoto:add-types-for-snowflake-connect
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
025abed
feat: Add types for `snowflake.connector.connect`
max-muoto 24a9d7e
Fix backoff types
max-muoto e5256e3
Various fixes
max-muoto e2d3188
Merge branch 'main' into add-types-for-snowflake-connect
max-muoto 566fac1
Minor typing tweaks
max-muoto f45b282
Merge branch 'main' into add-types-for-snowflake-connect
sfc-gh-mkubik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,12 +21,23 @@ | |
| from logging import getLogger | ||
| from threading import Lock | ||
| from types import TracebackType | ||
| from typing import Any, Callable, Generator, Iterable, Iterator, NamedTuple, Sequence | ||
| from typing import ( | ||
| TYPE_CHECKING, | ||
| Any, | ||
| Callable, | ||
| Generator, | ||
| Iterable, | ||
| Iterator, | ||
| NamedTuple, | ||
| Sequence, | ||
| TypedDict, | ||
| ) | ||
| from uuid import UUID | ||
|
|
||
| from cryptography.hazmat.backends import default_backend | ||
| from cryptography.hazmat.primitives import serialization | ||
| from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey | ||
| from typing_extensions import Unpack | ||
|
|
||
| from . import errors, proxy | ||
| from ._query_context_cache import QueryContextCache | ||
|
|
@@ -123,6 +134,10 @@ | |
| from .util_text import construct_hostname, parse_account, split_statements | ||
| from .wif_util import AttestationProvider | ||
|
|
||
| if TYPE_CHECKING: | ||
| from os import PathLike | ||
|
|
||
|
|
||
| DEFAULT_CLIENT_PREFETCH_THREADS = 4 | ||
| MAX_CLIENT_PREFETCH_THREADS = 10 | ||
| MAX_CLIENT_FETCH_THREADS = 1024 | ||
|
|
@@ -378,6 +393,53 @@ class TypeAndBinding(NamedTuple): | |
| binding: str | None | ||
|
|
||
|
|
||
| class SnowflakeConnectionConfig(TypedDict): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did You have a look at the DEFAULT_CONFIGURATION dictionary? It already contains list of supported config parameters. Maybe both could be merged into one entity? |
||
| """Configuration type for the SnowflakeConnection.""" | ||
|
|
||
| insecure_mode: bool | ||
| disable_ocsp_checks: bool | ||
| ocsp_fail_open: bool | ||
| session_id: int | ||
| user: str | ||
| host: str | ||
| port: int | ||
| region: str | ||
| proxy_host: str | ||
| proxy_port: str | ||
| proxy_user: str | ||
| proxy_password: str | ||
| account: str | ||
| database: str | ||
| schema: str | ||
| warehouse: str | ||
| role: str | ||
| login_timeout: int | ||
| network_timeout: int | ||
| socket_timeout: int | ||
| backoff_policy: Callable[[], Generator[int]] | ||
| client_session_keep_alive_heartbeat_frequency: int | ||
| client_prefetch_threads: int | ||
| client_fetch_threads: int | ||
| rest: SnowflakeRestful | ||
| application: str | ||
| errorhandler: Callable | ||
| converter_class: type[SnowflakeConverter] | ||
| validate_default_parameters: bool | ||
| is_pyformat: bool | ||
| consent_cache_id_token: str | ||
| enable_stage_s3_privatelink_for_us_east_1: bool | ||
| enable_connection_diag: bool | ||
| connection_diag_log_path: PathLike[str] | str | ||
| connection_diag_whitelist_path: PathLike[str] | str | ||
| connection_diag_allowlist_path: PathLike[str] | str | ||
| json_result_force_utf8_decoding: bool | ||
| server_session_keep_alive: bool | ||
| token_file_path: PathLike[str] | str | ||
| unsafe_file_write: bool | ||
| gcs_use_virtual_endpoints: bool | ||
| check_arrow_conversion_error_on_every_column: bool | ||
|
|
||
|
|
||
| class SnowflakeConnection: | ||
| """Implementation of the connection object for the Snowflake Database. | ||
|
|
||
|
|
@@ -448,8 +510,8 @@ class SnowflakeConnection: | |
| def __init__( | ||
| self, | ||
| connection_name: str | None = None, | ||
| connections_file_path: pathlib.Path | None = None, | ||
| **kwargs, | ||
| connections_file_path: PathLike[str] | None = None, | ||
| **kwargs: Unpack[SnowflakeConnectionConfig], | ||
| ) -> None: | ||
| """Create a new SnowflakeConnection. | ||
|
|
||
|
|
@@ -651,7 +713,7 @@ def socket_timeout(self) -> int | None: | |
| return int(self._socket_timeout) if self._socket_timeout is not None else None | ||
|
|
||
| @property | ||
| def _backoff_generator(self) -> Iterator: | ||
| def _backoff_generator(self) -> Generator[int]: | ||
| return self._backoff_policy() | ||
|
|
||
| @property | ||
|
|
@@ -983,7 +1045,7 @@ def autocommit(self, mode) -> None: | |
| except Error as e: | ||
| if e.sqlstate == SQLSTATE_FEATURE_NOT_SUPPORTED: | ||
| logger.debug( | ||
| "Autocommit feature is not enabled for this " "connection. Ignored" | ||
| "Autocommit feature is not enabled for this connection. Ignored" | ||
| ) | ||
|
|
||
| def commit(self) -> None: | ||
|
|
@@ -1166,7 +1228,7 @@ def __open_connection(self): | |
| elif self._authenticator == EXTERNAL_BROWSER_AUTHENTICATOR: | ||
| self._session_parameters[ | ||
| PARAMETER_CLIENT_STORE_TEMPORARY_CREDENTIAL | ||
| ] = (self._client_store_temporary_credential if IS_LINUX else True) | ||
| ] = self._client_store_temporary_credential if IS_LINUX else True | ||
| auth.read_temporary_credentials( | ||
| self.host, | ||
| self.user, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding more accurate types in this module to make sure these functions will properly fulfill the annotation for
backoff_policy