diff --git a/pyproject.toml b/pyproject.toml index 28364cb01..b7b4acaf0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -239,6 +239,7 @@ select = [ "RSE", # flake8-raise "RET", # flake8-return "SIM", # flake8-simplify + "TCH", # flake8-type-checking ] src = ["samples", "singer_sdk", "tests"] target-version = "py37" diff --git a/samples/sample_mapper/mapper.py b/samples/sample_mapper/mapper.py index 4aa3587ad..5f478c50a 100644 --- a/samples/sample_mapper/mapper.py +++ b/samples/sample_mapper/mapper.py @@ -2,8 +2,7 @@ from __future__ import annotations -from pathlib import PurePath -from typing import Generator +from typing import TYPE_CHECKING, Generator import singer_sdk._singerlib as singer import singer_sdk.typing as th @@ -11,6 +10,9 @@ from singer_sdk.mapper import PluginMapper from singer_sdk.mapper_base import InlineMapper +if TYPE_CHECKING: + from pathlib import PurePath + class StreamTransform(InlineMapper): """A map transformer which implements the Stream Maps capability.""" diff --git a/singer_sdk/_singerlib/messages.py b/singer_sdk/_singerlib/messages.py index 279037859..af195d031 100644 --- a/singer_sdk/_singerlib/messages.py +++ b/singer_sdk/_singerlib/messages.py @@ -6,11 +6,13 @@ import sys import typing as t from dataclasses import asdict, dataclass, field -from datetime import datetime import pytz import simplejson as json +if t.TYPE_CHECKING: + from datetime import datetime + class SingerMessageType(str, enum.Enum): """Singer specification message types.""" diff --git a/singer_sdk/authenticators.py b/singer_sdk/authenticators.py index 9fb8d656d..58ca0d7a7 100644 --- a/singer_sdk/authenticators.py +++ b/singer_sdk/authenticators.py @@ -3,11 +3,10 @@ from __future__ import annotations import base64 -import logging import math from datetime import datetime, timedelta from types import MappingProxyType -from typing import Any, Mapping +from typing import TYPE_CHECKING, Any, Mapping from urllib.parse import parse_qs, urlencode, urlsplit, urlunsplit import jwt @@ -16,7 +15,11 @@ from cryptography.hazmat.primitives import serialization from singer_sdk.helpers._util import utc_now -from singer_sdk.streams import Stream as RESTStreamBase + +if TYPE_CHECKING: + import logging + + from singer_sdk.streams import Stream as RESTStreamBase def _add_parameters(initial_url: str, extra_parameters: dict) -> str: diff --git a/singer_sdk/connectors/sql.py b/singer_sdk/connectors/sql.py index 8cf9bcb03..e1dd8a82e 100644 --- a/singer_sdk/connectors/sql.py +++ b/singer_sdk/connectors/sql.py @@ -7,16 +7,18 @@ from contextlib import contextmanager from datetime import datetime from functools import lru_cache -from typing import Any, Iterable, Iterator, cast +from typing import TYPE_CHECKING, Any, Iterable, Iterator, cast import sqlalchemy from sqlalchemy.engine import Engine -from sqlalchemy.engine.reflection import Inspector from singer_sdk import typing as th from singer_sdk._singerlib import CatalogEntry, MetadataMapping, Schema from singer_sdk.exceptions import ConfigValidationError +if TYPE_CHECKING: + from sqlalchemy.engine.reflection import Inspector + class SQLConnector: """Base class for SQLAlchemy-based connectors. diff --git a/singer_sdk/exceptions.py b/singer_sdk/exceptions.py index 5d7e91d94..c3b9bda42 100644 --- a/singer_sdk/exceptions.py +++ b/singer_sdk/exceptions.py @@ -2,7 +2,10 @@ from __future__ import annotations -import requests +import typing as t + +if t.TYPE_CHECKING: + import requests class ConfigValidationError(Exception): diff --git a/singer_sdk/helpers/_catalog.py b/singer_sdk/helpers/_catalog.py index c025868e0..cc91ff42b 100644 --- a/singer_sdk/helpers/_catalog.py +++ b/singer_sdk/helpers/_catalog.py @@ -3,14 +3,17 @@ from __future__ import annotations from copy import deepcopy -from logging import Logger -from typing import Any +from typing import TYPE_CHECKING, Any from memoization import cached -from singer_sdk._singerlib import Catalog, SelectionMask from singer_sdk.helpers._typing import is_object_type +if TYPE_CHECKING: + from logging import Logger + + from singer_sdk._singerlib import Catalog, SelectionMask + _MAX_LRU_CACHE = 500 diff --git a/singer_sdk/helpers/_resources.py b/singer_sdk/helpers/_resources.py index 5dc9655f7..9d40964ba 100644 --- a/singer_sdk/helpers/_resources.py +++ b/singer_sdk/helpers/_resources.py @@ -1,8 +1,10 @@ from __future__ import annotations import sys -from types import ModuleType -from typing import cast +from typing import TYPE_CHECKING, cast + +if TYPE_CHECKING: + from types import ModuleType if sys.version_info < (3, 9): import importlib_resources diff --git a/singer_sdk/helpers/_state.py b/singer_sdk/helpers/_state.py index 693e438b5..69909290c 100644 --- a/singer_sdk/helpers/_state.py +++ b/singer_sdk/helpers/_state.py @@ -2,12 +2,14 @@ from __future__ import annotations -import datetime -from typing import Any, Callable, cast +from typing import TYPE_CHECKING, Any, Callable, cast from singer_sdk.exceptions import InvalidStreamSortException from singer_sdk.helpers._typing import to_json_compatible +if TYPE_CHECKING: + import datetime + PROGRESS_MARKERS = "progress_markers" PROGRESS_MARKER_NOTE = "Note" SIGNPOST_MARKER = "replication_key_signpost" diff --git a/singer_sdk/helpers/_typing.py b/singer_sdk/helpers/_typing.py index 726b1aeac..a608ec7a4 100644 --- a/singer_sdk/helpers/_typing.py +++ b/singer_sdk/helpers/_typing.py @@ -4,13 +4,15 @@ import copy import datetime -import logging from enum import Enum from functools import lru_cache -from typing import Any, cast +from typing import TYPE_CHECKING, Any, cast import pendulum +if TYPE_CHECKING: + import logging + _MAX_TIMESTAMP = "9999-12-31 23:59:59.999999" _MAX_TIME = "23:59:59.999999" JSONSCHEMA_ANNOTATION_SECRET = "secret" diff --git a/singer_sdk/helpers/jsonpath.py b/singer_sdk/helpers/jsonpath.py index 6e96cd0b3..477e8c2de 100644 --- a/singer_sdk/helpers/jsonpath.py +++ b/singer_sdk/helpers/jsonpath.py @@ -2,12 +2,14 @@ from __future__ import annotations -from typing import Any, Generator +from typing import TYPE_CHECKING, Any, Generator -import jsonpath_ng import memoization from jsonpath_ng.ext import parse +if TYPE_CHECKING: + import jsonpath_ng + def extract_jsonpath(expression: str, input: dict | list) -> Generator[Any, None, None]: """Extract records from an input based on a JSONPath expression. diff --git a/singer_sdk/mapper.py b/singer_sdk/mapper.py index 34253a7e9..6efd6505d 100644 --- a/singer_sdk/mapper.py +++ b/singer_sdk/mapper.py @@ -10,10 +10,8 @@ import datetime import hashlib import logging -import sys -from typing import Any, Callable, Dict, Union +from typing import TYPE_CHECKING, Any, Callable, Dict, Union -from singer_sdk._singerlib.catalog import Catalog from singer_sdk.exceptions import MapExpressionError, StreamMapConfigError from singer_sdk.helpers import _simpleeval as simpleeval from singer_sdk.helpers._catalog import get_selected_schema @@ -33,10 +31,15 @@ StringType, ) -if sys.version_info >= (3, 10): - from typing import TypeAlias -else: - from typing_extensions import TypeAlias +if TYPE_CHECKING: + import sys + + if sys.version_info >= (3, 10): + from typing import TypeAlias + else: + from typing_extensions import TypeAlias + + from singer_sdk._singerlib.catalog import Catalog MAPPER_ELSE_OPTION = "__else__" diff --git a/singer_sdk/mapper_base.py b/singer_sdk/mapper_base.py index e17b23df5..0b3152625 100644 --- a/singer_sdk/mapper_base.py +++ b/singer_sdk/mapper_base.py @@ -3,8 +3,7 @@ from __future__ import annotations import abc -from io import FileIO -from typing import Callable, Iterable +from typing import TYPE_CHECKING, Callable, Iterable import click @@ -16,6 +15,9 @@ from singer_sdk.io_base import SingerReader from singer_sdk.plugin_base import PluginBase +if TYPE_CHECKING: + from io import FileIO + class InlineMapper(PluginBase, SingerReader, metaclass=abc.ABCMeta): """Abstract base class for inline mappers.""" diff --git a/singer_sdk/metrics.py b/singer_sdk/metrics.py index d6edb287a..1c69a3681 100644 --- a/singer_sdk/metrics.py +++ b/singer_sdk/metrics.py @@ -11,13 +11,15 @@ from dataclasses import asdict, dataclass, field from pathlib import Path from time import time -from types import TracebackType -from typing import Any, Generic, Mapping, TypeVar +from typing import TYPE_CHECKING, Any, Generic, Mapping, TypeVar import yaml from singer_sdk.helpers._resources import Traversable, get_package_files +if TYPE_CHECKING: + from types import TracebackType + DEFAULT_LOG_INTERVAL = 60.0 METRICS_LOGGER_NAME = __name__ METRICS_LOG_LEVEL_SETTING = "metrics_log_level" diff --git a/singer_sdk/pagination.py b/singer_sdk/pagination.py index a6df551ba..52abaf2f2 100644 --- a/singer_sdk/pagination.py +++ b/singer_sdk/pagination.py @@ -4,11 +4,9 @@ import sys from abc import ABCMeta, abstractmethod -from typing import Any, Generic, Iterable, Optional, TypeVar +from typing import TYPE_CHECKING, Any, Generic, Iterable, Optional, TypeVar from urllib.parse import ParseResult, urlparse -from requests import Response - from singer_sdk.helpers.jsonpath import extract_jsonpath if sys.version_info >= (3, 8): @@ -16,6 +14,9 @@ else: from typing_extensions import Protocol +if TYPE_CHECKING: + from requests import Response + T = TypeVar("T") TPageToken = TypeVar("TPageToken") diff --git a/singer_sdk/plugin_base.py b/singer_sdk/plugin_base.py index 49cb00074..60c8d7ed7 100644 --- a/singer_sdk/plugin_base.py +++ b/singer_sdk/plugin_base.py @@ -9,7 +9,7 @@ from collections import OrderedDict from pathlib import PurePath from types import MappingProxyType -from typing import Any, Callable, Mapping, cast +from typing import TYPE_CHECKING, Any, Callable, Mapping, cast import click from jsonschema import Draft7Validator @@ -27,9 +27,11 @@ CapabilitiesEnum, PluginCapabilities, ) -from singer_sdk.mapper import PluginMapper from singer_sdk.typing import extend_validator_with_defaults +if TYPE_CHECKING: + from singer_sdk.mapper import PluginMapper + SDK_PACKAGE_NAME = "singer_sdk" diff --git a/singer_sdk/sinks/core.py b/singer_sdk/sinks/core.py index 9e58e165c..219581014 100644 --- a/singer_sdk/sinks/core.py +++ b/singer_sdk/sinks/core.py @@ -8,9 +8,8 @@ import time from gzip import GzipFile from gzip import open as gzip_open -from logging import Logger from types import MappingProxyType -from typing import IO, Any, Mapping, Sequence +from typing import IO, TYPE_CHECKING, Any, Mapping, Sequence from dateutil import parser from jsonschema import Draft7Validator, FormatChecker @@ -27,7 +26,11 @@ get_datelike_property_type, handle_invalid_timestamp_in_record, ) -from singer_sdk.plugin_base import PluginBase + +if TYPE_CHECKING: + from logging import Logger + + from singer_sdk.plugin_base import PluginBase JSONSchemaValidator = Draft7Validator diff --git a/singer_sdk/sinks/sql.py b/singer_sdk/sinks/sql.py index f975dacab..4f5f8889a 100644 --- a/singer_sdk/sinks/sql.py +++ b/singer_sdk/sinks/sql.py @@ -6,19 +6,22 @@ from collections import defaultdict from copy import copy from textwrap import dedent -from typing import Any, Iterable +from typing import TYPE_CHECKING, Any, Iterable import sqlalchemy from pendulum import now -from sqlalchemy.sql import Executable from sqlalchemy.sql.expression import bindparam from singer_sdk.connectors import SQLConnector from singer_sdk.exceptions import ConformedNameClashException from singer_sdk.helpers._conformers import replace_leading_digit -from singer_sdk.plugin_base import PluginBase from singer_sdk.sinks.batch import BatchSink +if TYPE_CHECKING: + from sqlalchemy.sql import Executable + + from singer_sdk.plugin_base import PluginBase + class SQLSink(BatchSink): """SQL-type sink type.""" diff --git a/singer_sdk/streams/core.py b/singer_sdk/streams/core.py index c929c103e..bd789c849 100644 --- a/singer_sdk/streams/core.py +++ b/singer_sdk/streams/core.py @@ -8,11 +8,19 @@ import gzip import itertools import json -import logging from os import PathLike from pathlib import Path from types import MappingProxyType -from typing import Any, Generator, Iterable, Iterator, Mapping, TypeVar, cast +from typing import ( + TYPE_CHECKING, + Any, + Generator, + Iterable, + Iterator, + Mapping, + TypeVar, + cast, +) from uuid import uuid4 import pendulum @@ -46,7 +54,11 @@ ) from singer_sdk.helpers._util import utc_now from singer_sdk.mapper import RemoveRecordTransform, SameRecordTransform, StreamMap -from singer_sdk.plugin_base import PluginBase as TapBaseClass + +if TYPE_CHECKING: + import logging + + from singer_sdk.plugin_base import PluginBase as TapBaseClass # Replication methods REPLICATION_FULL_TABLE = "FULL_TABLE" diff --git a/singer_sdk/streams/rest.py b/singer_sdk/streams/rest.py index cdf20c224..fc66dd5bf 100644 --- a/singer_sdk/streams/rest.py +++ b/singer_sdk/streams/rest.py @@ -5,8 +5,6 @@ import abc import copy import logging -import sys -from datetime import datetime from typing import TYPE_CHECKING, Any, Callable, Generator, Generic, Iterable, TypeVar from urllib.parse import urlparse from warnings import warn @@ -15,7 +13,6 @@ import requests from singer_sdk import metrics -from singer_sdk._singerlib import Schema from singer_sdk.authenticators import SimpleAuthenticator from singer_sdk.exceptions import FatalAPIError, RetriableAPIError from singer_sdk.helpers.jsonpath import extract_jsonpath @@ -25,17 +22,22 @@ LegacyStreamPaginator, SimpleHeaderPaginator, ) -from singer_sdk.plugin_base import PluginBase as TapBaseClass from singer_sdk.streams.core import Stream -if sys.version_info >= (3, 10): - from typing import TypeAlias -else: - from typing_extensions import TypeAlias - if TYPE_CHECKING: + import sys + from datetime import datetime + from backoff.types import Details + from singer_sdk._singerlib import Schema + from singer_sdk.plugin_base import PluginBase as TapBaseClass + + if sys.version_info >= (3, 10): + from typing import TypeAlias + else: + from typing_extensions import TypeAlias + DEFAULT_PAGE_SIZE = 1000 DEFAULT_REQUEST_TIMEOUT = 300 # 5 minutes diff --git a/singer_sdk/streams/sql.py b/singer_sdk/streams/sql.py index 04c6db313..8fb1a2dc0 100644 --- a/singer_sdk/streams/sql.py +++ b/singer_sdk/streams/sql.py @@ -3,16 +3,18 @@ from __future__ import annotations import abc -from typing import Any, Iterable, cast +from typing import TYPE_CHECKING, Any, Iterable, cast import sqlalchemy import singer_sdk.helpers._catalog as catalog from singer_sdk._singerlib import CatalogEntry, MetadataMapping from singer_sdk.connectors import SQLConnector -from singer_sdk.plugin_base import PluginBase as TapBaseClass from singer_sdk.streams.core import Stream +if TYPE_CHECKING: + from singer_sdk.plugin_base import PluginBase as TapBaseClass + class SQLStream(Stream, metaclass=abc.ABCMeta): """Base class for SQLAlchemy-based streams.""" diff --git a/singer_sdk/tap_base.py b/singer_sdk/tap_base.py index 2e9e8ca86..5ad9e0e9d 100644 --- a/singer_sdk/tap_base.py +++ b/singer_sdk/tap_base.py @@ -7,7 +7,7 @@ import json from enum import Enum from pathlib import Path, PurePath -from typing import Any, Callable, Sequence, cast +from typing import TYPE_CHECKING, Any, Callable, Sequence, cast import click @@ -26,7 +26,9 @@ ) from singer_sdk.mapper import PluginMapper from singer_sdk.plugin_base import PluginBase -from singer_sdk.streams import SQLStream, Stream + +if TYPE_CHECKING: + from singer_sdk.streams import SQLStream, Stream STREAM_MAPS_CONFIG = "stream_maps" diff --git a/singer_sdk/target_base.py b/singer_sdk/target_base.py index f2a34009e..a5022c80d 100644 --- a/singer_sdk/target_base.py +++ b/singer_sdk/target_base.py @@ -7,9 +7,8 @@ import json import sys import time -from io import FileIO from pathlib import Path, PurePath -from typing import IO, Callable, Counter +from typing import IO, TYPE_CHECKING, Callable, Counter import click from joblib import Parallel, delayed, parallel_backend @@ -28,7 +27,11 @@ from singer_sdk.io_base import SingerMessageType, SingerReader from singer_sdk.mapper import PluginMapper from singer_sdk.plugin_base import PluginBase -from singer_sdk.sinks import Sink + +if TYPE_CHECKING: + from io import FileIO + + from singer_sdk.sinks import Sink _MAX_PARALLELISM = 8 diff --git a/singer_sdk/testing/factory.py b/singer_sdk/testing/factory.py index 62638ec4b..1c90f2d68 100644 --- a/singer_sdk/testing/factory.py +++ b/singer_sdk/testing/factory.py @@ -2,12 +2,10 @@ from __future__ import annotations -from typing import Any, cast +from typing import TYPE_CHECKING, Any, cast import pytest -from singer_sdk import Tap, Target - from .config import SuiteConfig from .runners import TapTestRunner, TargetTestRunner from .suites import ( @@ -17,6 +15,9 @@ target_tests, ) +if TYPE_CHECKING: + from singer_sdk import Tap, Target + def get_test_class( test_runner: TapTestRunner | TargetTestRunner, diff --git a/singer_sdk/testing/legacy.py b/singer_sdk/testing/legacy.py index d7ef3c155..5c1204537 100644 --- a/singer_sdk/testing/legacy.py +++ b/singer_sdk/testing/legacy.py @@ -4,12 +4,14 @@ import io from contextlib import redirect_stderr, redirect_stdout -from typing import Callable, cast +from typing import TYPE_CHECKING, Callable, cast import singer_sdk._singerlib as singer -from singer_sdk.mapper_base import InlineMapper -from singer_sdk.tap_base import Tap -from singer_sdk.target_base import Target + +if TYPE_CHECKING: + from singer_sdk.mapper_base import InlineMapper + from singer_sdk.tap_base import Tap + from singer_sdk.target_base import Target def get_standard_tap_tests( diff --git a/singer_sdk/testing/runners.py b/singer_sdk/testing/runners.py index c70afa91c..9c60ea9a8 100644 --- a/singer_sdk/testing/runners.py +++ b/singer_sdk/testing/runners.py @@ -7,12 +7,14 @@ import json from collections import defaultdict from contextlib import redirect_stderr, redirect_stdout -from pathlib import Path -from typing import IO, Any, cast +from typing import IO, TYPE_CHECKING, Any, cast from singer_sdk import Tap, Target from singer_sdk.testing.config import SuiteConfig +if TYPE_CHECKING: + from pathlib import Path + class SingerTestRunner(metaclass=abc.ABCMeta): """Base Singer Test Runner.""" diff --git a/singer_sdk/testing/suites.py b/singer_sdk/testing/suites.py index 66d093c7f..068d1ea31 100644 --- a/singer_sdk/testing/suites.py +++ b/singer_sdk/testing/suites.py @@ -2,6 +2,7 @@ from __future__ import annotations +import typing as t from dataclasses import dataclass from .tap_tests import ( @@ -38,7 +39,9 @@ TargetSchemaUpdates, TargetSpecialCharsInAttributes, ) -from .templates import TapTestTemplate, TargetTestTemplate, TestTemplate + +if t.TYPE_CHECKING: + from .templates import TapTestTemplate, TargetTestTemplate, TestTemplate @dataclass diff --git a/singer_sdk/testing/tap_tests.py b/singer_sdk/testing/tap_tests.py index 44ea43438..ecffc4955 100644 --- a/singer_sdk/testing/tap_tests.py +++ b/singer_sdk/testing/tap_tests.py @@ -3,16 +3,18 @@ from __future__ import annotations import warnings -from typing import Type, cast +from typing import TYPE_CHECKING, Type, cast from dateutil import parser import singer_sdk.helpers._typing as th from singer_sdk import Tap -from singer_sdk.streams.core import Stream from .templates import AttributeTestTemplate, StreamTestTemplate, TapTestTemplate +if TYPE_CHECKING: + from singer_sdk.streams.core import Stream + class TapCLIPrintsTest(TapTestTemplate): """Test that the tap is able to print standard metadata.""" diff --git a/singer_sdk/testing/templates.py b/singer_sdk/testing/templates.py index 18a052993..5359ba08f 100644 --- a/singer_sdk/testing/templates.py +++ b/singer_sdk/testing/templates.py @@ -6,12 +6,13 @@ import os import warnings from pathlib import Path -from typing import Any +from typing import TYPE_CHECKING, Any -from singer_sdk.streams import Stream +if TYPE_CHECKING: + from singer_sdk.streams import Stream -from .config import SuiteConfig -from .runners import TapTestRunner, TargetTestRunner + from .config import SuiteConfig + from .runners import TapTestRunner, TargetTestRunner class TestTemplate: diff --git a/singer_sdk/typing.py b/singer_sdk/typing.py index 646fa58e2..fe837ef7f 100644 --- a/singer_sdk/typing.py +++ b/singer_sdk/typing.py @@ -46,8 +46,8 @@ from __future__ import annotations import json -import sys from typing import ( + TYPE_CHECKING, Any, Generator, Generic, @@ -70,10 +70,14 @@ get_datelike_property_type, ) -if sys.version_info >= (3, 10): - from typing import TypeAlias -else: - from typing_extensions import TypeAlias +if TYPE_CHECKING: + import sys + + if sys.version_info >= (3, 10): + from typing import TypeAlias + else: + from typing_extensions import TypeAlias + __all__ = [ "extend_validator_with_defaults", diff --git a/tests/conftest.py b/tests/conftest.py index 2ec670257..0f5c2193a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,9 +6,12 @@ import pathlib import platform import shutil +import typing as t import pytest -from _pytest.config import Config + +if t.TYPE_CHECKING: + from _pytest.config import Config SYSTEMS = {"linux", "darwin", "windows"} diff --git a/tests/core/rest/test_authenticators.py b/tests/core/rest/test_authenticators.py index 3eb1c6b7c..fa42caef5 100644 --- a/tests/core/rest/test_authenticators.py +++ b/tests/core/rest/test_authenticators.py @@ -2,9 +2,10 @@ from __future__ import annotations +import typing as t + import jwt import pytest -import requests_mock from cryptography.hazmat.primitives.asymmetric.rsa import ( RSAPrivateKey, RSAPublicKey, @@ -19,8 +20,12 @@ from requests.auth import HTTPProxyAuth, _basic_auth_str from singer_sdk.authenticators import OAuthAuthenticator, OAuthJWTAuthenticator -from singer_sdk.streams import RESTStream -from singer_sdk.tap_base import Tap + +if t.TYPE_CHECKING: + import requests_mock + + from singer_sdk.streams import RESTStream + from singer_sdk.tap_base import Tap @pytest.mark.parametrize( diff --git a/tests/core/test_jsonschema_helpers.py b/tests/core/test_jsonschema_helpers.py index 28fc40d1b..6a4ef0ba6 100644 --- a/tests/core/test_jsonschema_helpers.py +++ b/tests/core/test_jsonschema_helpers.py @@ -3,12 +3,10 @@ from __future__ import annotations import re -from pathlib import Path from textwrap import dedent -from typing import Callable +from typing import TYPE_CHECKING, Callable import pytest -from pytest_snapshot.plugin import Snapshot from singer_sdk.helpers._typing import ( JSONSCHEMA_ANNOTATION_SECRET, @@ -25,7 +23,6 @@ is_string_array_type, is_string_type, ) -from singer_sdk.streams.core import Stream from singer_sdk.tap_base import Tap from singer_sdk.typing import ( ArrayType, @@ -55,6 +52,13 @@ UUIDType, ) +if TYPE_CHECKING: + from pathlib import Path + + from pytest_snapshot.plugin import Snapshot + + from singer_sdk.streams.core import Stream + TYPE_FN_CHECKS: set[Callable] = { is_array_type, is_boolean_type, diff --git a/tests/core/test_mapper.py b/tests/core/test_mapper.py index 00c3fb22f..06b885cf0 100644 --- a/tests/core/test_mapper.py +++ b/tests/core/test_mapper.py @@ -6,12 +6,11 @@ import io import json import logging +import typing as t from contextlib import redirect_stdout -from pathlib import Path import pytest from freezegun import freeze_time -from pytest_snapshot.plugin import Snapshot from singer_sdk._singerlib import Catalog from singer_sdk.exceptions import MapExpressionError @@ -27,6 +26,11 @@ StringType, ) +if t.TYPE_CHECKING: + from pathlib import Path + + from pytest_snapshot.plugin import Snapshot + @pytest.fixture def stream_map_config() -> dict: diff --git a/tests/core/test_plugin_config.py b/tests/core/test_plugin_config.py index 5b26d7442..8e23d4b54 100644 --- a/tests/core/test_plugin_config.py +++ b/tests/core/test_plugin_config.py @@ -3,12 +3,14 @@ from __future__ import annotations -from typing import Any +from typing import TYPE_CHECKING, Any -from singer_sdk.streams.core import Stream from singer_sdk.tap_base import Tap from singer_sdk.typing import BooleanType, PropertiesList, Property +if TYPE_CHECKING: + from singer_sdk.streams.core import Stream + SAMPLE_CONFIG: dict[str, Any] = {} diff --git a/tests/core/test_typing.py b/tests/core/test_typing.py index e08e31beb..60a223c1a 100644 --- a/tests/core/test_typing.py +++ b/tests/core/test_typing.py @@ -4,8 +4,7 @@ import datetime import logging - -import pytest +import typing as t from singer_sdk.helpers._typing import ( TypeConformanceLevel, @@ -20,6 +19,9 @@ StringType, ) +if t.TYPE_CHECKING: + import pytest + logger = logging.getLogger("log") diff --git a/tests/samples/test_tap_sqlite.py b/tests/samples/test_tap_sqlite.py index 958cc9ed2..b882f4c4c 100644 --- a/tests/samples/test_tap_sqlite.py +++ b/tests/samples/test_tap_sqlite.py @@ -1,17 +1,20 @@ from __future__ import annotations -from pathlib import Path -from typing import cast +from typing import TYPE_CHECKING, cast from samples.sample_target_csv.csv_target import SampleTargetCSV from singer_sdk import SQLStream from singer_sdk._singerlib import MetadataMapping, StreamMetadata -from singer_sdk.tap_base import SQLTap from singer_sdk.testing import ( get_standard_tap_tests, tap_to_target_sync_test, ) +if TYPE_CHECKING: + from pathlib import Path + + from singer_sdk.tap_base import SQLTap + def _discover_and_select_all(tap: SQLTap) -> None: """Discover catalog and auto-select all streams.""" diff --git a/tests/samples/test_target_sqlite.py b/tests/samples/test_target_sqlite.py index 67bad4e75..4b83ce60d 100644 --- a/tests/samples/test_target_sqlite.py +++ b/tests/samples/test_target_sqlite.py @@ -4,6 +4,7 @@ import json import sqlite3 +import typing as t from copy import deepcopy from io import StringIO from pathlib import Path @@ -17,8 +18,6 @@ from samples.sample_tap_sqlite import SQLiteTap from samples.sample_target_sqlite import SQLiteSink, SQLiteTarget from singer_sdk import typing as th -from singer_sdk.tap_base import SQLTap -from singer_sdk.target_base import SQLTarget from singer_sdk.testing import ( _get_tap_catalog, tap_sync_test, @@ -26,6 +25,10 @@ target_sync_test, ) +if t.TYPE_CHECKING: + from singer_sdk.tap_base import SQLTap + from singer_sdk.target_base import SQLTarget + @pytest.fixture def path_to_target_db(tmp_path: Path) -> Path: