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

refactor: Use future warnings.deprecated decorator #2647

Merged
Merged
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
17 changes: 10 additions & 7 deletions singer_sdk/authenticators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
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

import requests

from singer_sdk.helpers._util import utc_now

if sys.version_info < (3, 13):
from typing_extensions import deprecated
else:
from warnings import deprecated

Check warning on line 20 in singer_sdk/authenticators.py

View check run for this annotation

Codecov / codecov/patch

singer_sdk/authenticators.py#L20

Added line #L20 was not covered by tests

if t.TYPE_CHECKING:
import logging

Expand Down Expand Up @@ -277,6 +282,10 @@
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.

Expand All @@ -302,12 +311,6 @@
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")
Expand Down
34 changes: 20 additions & 14 deletions singer_sdk/connectors/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import logging
import sys
import typing as t
import warnings
from collections import UserString
Expand All @@ -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

Check warning on line 25 in singer_sdk/connectors/sql.py

View check run for this annotation

Codecov / codecov/patch

singer_sdk/connectors/sql.py#L25

Added line #L25 was not covered by tests

if t.TYPE_CHECKING:
from sqlalchemy.engine import Engine
from sqlalchemy.engine.reflection import Inspector
Expand Down Expand Up @@ -161,6 +167,14 @@
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.

Expand All @@ -180,16 +194,14 @@
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.

Expand All @@ -199,12 +211,6 @@
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
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_connector_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Loading