diff --git a/singer_sdk/authenticators.py b/singer_sdk/authenticators.py index 4c15304e5..3a7fd8833 100644 --- a/singer_sdk/authenticators.py +++ b/singer_sdk/authenticators.py @@ -5,8 +5,8 @@ import base64 import datetime import math +import sys import typing as t -import warnings from types import MappingProxyType from urllib.parse import parse_qs, urlencode, urlsplit, urlunsplit @@ -14,6 +14,11 @@ from singer_sdk.helpers._util import utc_now +if sys.version_info < (3, 13): + from typing_extensions import deprecated +else: + from warnings import deprecated + if t.TYPE_CHECKING: import logging @@ -277,6 +282,10 @@ def create_for_stream( return cls(stream=stream, token=token) +@deprecated( + "BasicAuthenticator is deprecated. Use requests.auth.HTTPBasicAuth instead.", + category=DeprecationWarning, +) class BasicAuthenticator(APIAuthenticatorBase): """Implements basic authentication for REST Streams. @@ -302,12 +311,6 @@ def __init__( password: API password. """ super().__init__(stream=stream) - warnings.warn( - "BasicAuthenticator is deprecated. Use " - "requests.auth.HTTPBasicAuth instead.", - DeprecationWarning, - stacklevel=2, - ) credentials = f"{username}:{password}".encode() auth_token = base64.b64encode(credentials).decode("ascii") diff --git a/singer_sdk/connectors/sql.py b/singer_sdk/connectors/sql.py index c9f18cbf3..c79c6308f 100644 --- a/singer_sdk/connectors/sql.py +++ b/singer_sdk/connectors/sql.py @@ -3,6 +3,7 @@ from __future__ import annotations import logging +import sys import typing as t import warnings from collections import UserString @@ -18,6 +19,11 @@ from singer_sdk.helpers._util import dump_json, load_json from singer_sdk.helpers.capabilities import TargetLoadMethods +if sys.version_info < (3, 13): + from typing_extensions import deprecated +else: + from warnings import deprecated + if t.TYPE_CHECKING: from sqlalchemy.engine import Engine from sqlalchemy.engine.reflection import Inspector @@ -161,6 +167,14 @@ def _connect(self) -> t.Iterator[sa.engine.Connection]: with self._engine.connect().execution_options(stream_results=True) as conn: yield conn + @deprecated( + "`SQLConnector.create_sqlalchemy_connection` is deprecated. " + "If you need to execute something that isn't available " + "on the connector currently, make a child class and " + "add your required method on that connector.", + category=DeprecationWarning, + stacklevel=1, + ) def create_sqlalchemy_connection(self) -> sa.engine.Connection: """(DEPRECATED) Return a new SQLAlchemy connection using the provided config. @@ -180,16 +194,14 @@ def create_sqlalchemy_connection(self) -> sa.engine.Connection: Returns: A newly created SQLAlchemy engine object. """ - warnings.warn( - "`SQLConnector.create_sqlalchemy_connection` is deprecated. " - "If you need to execute something that isn't available " - "on the connector currently, make a child class and " - "add your required method on that connector.", - DeprecationWarning, - stacklevel=2, - ) return self._engine.connect().execution_options(stream_results=True) + @deprecated( + "`SQLConnector.create_sqlalchemy_engine` is deprecated. Override " + "`_engine` or `sqlalchemy_url` instead.", + category=DeprecationWarning, + stacklevel=1, + ) def create_sqlalchemy_engine(self) -> Engine: """(DEPRECATED) Return a new SQLAlchemy engine using the provided config. @@ -199,12 +211,6 @@ def create_sqlalchemy_engine(self) -> Engine: Returns: A newly created SQLAlchemy engine object. """ - warnings.warn( - "`SQLConnector.create_sqlalchemy_engine` is deprecated. Override" - "`_engine` or sqlalchemy_url` instead.", - DeprecationWarning, - stacklevel=2, - ) return self._engine @property diff --git a/tests/core/test_connector_sql.py b/tests/core/test_connector_sql.py index c8390f33d..f37fb953b 100644 --- a/tests/core/test_connector_sql.py +++ b/tests/core/test_connector_sql.py @@ -156,7 +156,7 @@ def test_engine_creates_and_returns_cached_engine(self, connector): engine2 = connector._cached_engine assert engine1 is engine2 - def test_deprecated_functions_warn(self, connector): + def test_deprecated_functions_warn(self, connector: SQLConnector): with pytest.deprecated_call(): connector.create_sqlalchemy_engine() with pytest.deprecated_call():