diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 12ea90545..4b45f70d1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,14 +37,14 @@ repos: - id: trailing-whitespace - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.29.4 + rev: 0.30.0 hooks: - id: check-dependabot - id: check-github-workflows - id: check-readthedocs - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.0 + rev: v0.8.1 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix, --show-fixes] diff --git a/samples/sample_tap_gitlab/gitlab_rest_streams.py b/samples/sample_tap_gitlab/gitlab_rest_streams.py index 5ed59f666..6fb1e5640 100644 --- a/samples/sample_tap_gitlab/gitlab_rest_streams.py +++ b/samples/sample_tap_gitlab/gitlab_rest_streams.py @@ -74,7 +74,7 @@ def partitions(self) -> list[dict]: if "{project_id}" in self.path: return [ {"project_id": pid} - for pid in t.cast(list, self.config.get("project_ids")) + for pid in t.cast("list", self.config.get("project_ids")) ] if "{group_id}" in self.path: if "group_ids" not in self.config: @@ -84,7 +84,8 @@ def partitions(self) -> list[dict]: ) raise ValueError(msg) return [ - {"group_id": gid} for gid in t.cast(list, self.config.get("group_ids")) + {"group_id": gid} + for gid in t.cast("list", self.config.get("group_ids")) ] msg = ( f"Could not detect partition type for Gitlab stream '{self.name}' " diff --git a/singer_sdk/connectors/sql.py b/singer_sdk/connectors/sql.py index 6ec100023..540de023e 100644 --- a/singer_sdk/connectors/sql.py +++ b/singer_sdk/connectors/sql.py @@ -641,7 +641,7 @@ def get_sqlalchemy_url(self, config: dict[str, t.Any]) -> str: # noqa: PLR6301 msg = "Could not find or create 'sqlalchemy_url' for connection." raise ConfigValidationError(msg) - return t.cast(str, config["sqlalchemy_url"]) + return t.cast("str", config["sqlalchemy_url"]) def to_jsonschema_type( self, @@ -1429,7 +1429,7 @@ def _get_type_sort_key( _len = int(getattr(sql_type, "length", 0) or 0) - _pytype = t.cast(type, sql_type.python_type) + _pytype = t.cast("type", sql_type.python_type) if issubclass(_pytype, (str, bytes)): return 900, _len if issubclass(_pytype, datetime): diff --git a/singer_sdk/helpers/_state.py b/singer_sdk/helpers/_state.py index 565dbd51d..9b0aa7be1 100644 --- a/singer_sdk/helpers/_state.py +++ b/singer_sdk/helpers/_state.py @@ -125,7 +125,7 @@ def get_writeable_state_dict( tap_state["bookmarks"] = {} if tap_stream_id not in tap_state["bookmarks"]: tap_state["bookmarks"][tap_stream_id] = {} - stream_state = t.cast(dict, tap_state["bookmarks"][tap_stream_id]) + stream_state = t.cast("dict", tap_state["bookmarks"][tap_stream_id]) if not state_partition_context: return stream_state diff --git a/singer_sdk/helpers/_typing.py b/singer_sdk/helpers/_typing.py index d3b629c11..b916d886b 100644 --- a/singer_sdk/helpers/_typing.py +++ b/singer_sdk/helpers/_typing.py @@ -187,11 +187,11 @@ def get_datelike_property_type(property_schema: dict) -> str | None: Otherwise return None. """ if _is_string_with_format(property_schema): - return t.cast(str, property_schema["format"]) + return t.cast("str", property_schema["format"]) if "anyOf" in property_schema: for type_dict in property_schema["anyOf"]: if _is_string_with_format(type_dict): - return t.cast(str, type_dict["format"]) + return t.cast("str", type_dict["format"]) return None diff --git a/singer_sdk/plugin_base.py b/singer_sdk/plugin_base.py index f12f15227..1b8735f2f 100644 --- a/singer_sdk/plugin_base.py +++ b/singer_sdk/plugin_base.py @@ -384,7 +384,7 @@ def config(self) -> t.Mapping[str, t.Any]: Returns: A frozen (read-only) config dictionary map. """ - return t.cast(dict, MappingProxyType(self._config)) + return t.cast("dict", MappingProxyType(self._config)) @staticmethod def _is_secret_config(config_key: str) -> bool: diff --git a/singer_sdk/tap_base.py b/singer_sdk/tap_base.py index 82900049c..ea6f96beb 100644 --- a/singer_sdk/tap_base.py +++ b/singer_sdk/tap_base.py @@ -316,7 +316,7 @@ def catalog_dict(self) -> dict: Returns: The tap's catalog as a dict """ - return t.cast(dict, self._singer_catalog.to_dict()) + return t.cast("dict", self._singer_catalog.to_dict()) @property def catalog_json_text(self) -> str: diff --git a/singer_sdk/testing/legacy.py b/singer_sdk/testing/legacy.py index eae4c5b5d..30849abd1 100644 --- a/singer_sdk/testing/legacy.py +++ b/singer_sdk/testing/legacy.py @@ -166,7 +166,7 @@ def _select_all(catalog_dict: dict) -> dict: for catalog_entry in catalog.streams: catalog_entry.metadata.root.selected = True - return t.cast(dict, catalog.to_dict()) + return t.cast("dict", catalog.to_dict()) def target_sync_test( diff --git a/singer_sdk/testing/runners.py b/singer_sdk/testing/runners.py index 9ef644d02..145f44deb 100644 --- a/singer_sdk/testing/runners.py +++ b/singer_sdk/testing/runners.py @@ -9,12 +9,12 @@ from collections import defaultdict from contextlib import redirect_stderr, redirect_stdout -from singer_sdk import Tap, Target from singer_sdk.testing.config import SuiteConfig if t.TYPE_CHECKING: from pathlib import Path + from singer_sdk import Tap, Target from singer_sdk.helpers._compat import Traversable @@ -115,7 +115,7 @@ def new_tap(self) -> Tap: Returns: A configured Tap instance. """ - return t.cast(Tap, self.create()) + return t.cast("Tap", self.create()) def run_discovery(self) -> str: """Run tap discovery. @@ -233,7 +233,7 @@ def new_target(self) -> Target: Returns: A configured Target instance. """ - return t.cast(Target, self.create()) + return t.cast("Target", self.create()) @property def target_input(self) -> t.IO[str]: @@ -247,7 +247,7 @@ def target_input(self) -> t.IO[str]: self._input = self.input_io elif self.input_filepath: self._input = self.input_filepath.open(encoding="utf8") - return t.cast(t.IO[str], self._input) + return t.cast("t.IO[str]", self._input) @target_input.setter def target_input(self, value: t.IO[str]) -> None: diff --git a/singer_sdk/testing/tap_tests.py b/singer_sdk/testing/tap_tests.py index 54352c694..b5e936b26 100644 --- a/singer_sdk/testing/tap_tests.py +++ b/singer_sdk/testing/tap_tests.py @@ -43,7 +43,7 @@ def test(self) -> None: catalog = tap1.catalog_dict # Reset and re-initialize with discovered catalog kwargs = {k: v for k, v in self.runner.default_kwargs.items() if k != "catalog"} - tap2: Tap = t.cast(type[Tap], self.runner.singer_class)( + tap2: Tap = t.cast("type[Tap]", self.runner.singer_class)( config=self.runner.config, catalog=catalog, **kwargs, diff --git a/singer_sdk/typing.py b/singer_sdk/typing.py index fb22f4e82..336eb6995 100644 --- a/singer_sdk/typing.py +++ b/singer_sdk/typing.py @@ -703,7 +703,7 @@ def type_dict(self) -> dict: # type: ignore[override] # TODO: this should be a TypeError, but it's a breaking change. raise ValueError(msg) # noqa: TRY004 - return t.cast(dict, wrapped.type_dict) + return t.cast("dict", wrapped.type_dict) def to_dict(self) -> dict: """Return a dict mapping the property name to its definition. diff --git a/tests/samples/test_tap_sqlite.py b/tests/samples/test_tap_sqlite.py index ff83de338..a59c4a08e 100644 --- a/tests/samples/test_tap_sqlite.py +++ b/tests/samples/test_tap_sqlite.py @@ -10,7 +10,6 @@ from samples.sample_tap_sqlite import SQLiteTap from samples.sample_target_csv.csv_target import SampleTargetCSV -from singer_sdk import SQLStream from singer_sdk._singerlib import MetadataMapping, StreamMetadata from singer_sdk.testing import ( get_standard_tap_tests, @@ -21,6 +20,7 @@ if t.TYPE_CHECKING: from pathlib import Path + from singer_sdk import SQLStream from singer_sdk.tap_base import SQLTap @@ -50,7 +50,7 @@ def test_tap_sqlite_cli(sqlite_sample_db_config: dict[str, t.Any], tmp_path: Pat def test_sql_metadata(sqlite_sample_tap: SQLTap): - stream = t.cast(SQLStream, sqlite_sample_tap.streams["main-t1"]) + stream = t.cast("SQLStream", sqlite_sample_tap.streams["main-t1"]) detected_metadata = stream.catalog_entry["metadata"] detected_root_md = next(md for md in detected_metadata if md["breadcrumb"] == []) detected_root_md = detected_root_md["metadata"] @@ -68,7 +68,7 @@ def test_sql_metadata(sqlite_sample_tap: SQLTap): def test_sqlite_discovery(sqlite_sample_tap: SQLTap): _discover_and_select_all(sqlite_sample_tap) sqlite_sample_tap.sync_all() - stream = t.cast(SQLStream, sqlite_sample_tap.streams["main-t1"]) + stream = t.cast("SQLStream", sqlite_sample_tap.streams["main-t1"]) schema = stream.schema assert len(schema["properties"]) == 3 assert stream.name == stream.tap_stream_id == "main-t1" @@ -89,7 +89,7 @@ def test_sqlite_discovery(sqlite_sample_tap: SQLTap): def test_sqlite_input_catalog(sqlite_sample_tap: SQLTap): sqlite_sample_tap.sync_all() - stream = t.cast(SQLStream, sqlite_sample_tap.streams["main-t1"]) + stream = t.cast("SQLStream", sqlite_sample_tap.streams["main-t1"]) assert len(stream.schema["properties"]) == 3 assert len(stream.stream_maps[0].transformed_schema["properties"]) == 3