From 019902ed7015c20b2b8b7dad04edd7e8b16468bd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 25 Jul 2023 10:22:36 -0600 Subject: [PATCH] chore: pre-commit autoupdate (#1875) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Edgar Ramírez Mondragón --- .pre-commit-config.yaml | 2 +- singer_sdk/connectors/sql.py | 2 +- singer_sdk/helpers/_flattening.py | 18 +++++++++--------- singer_sdk/streams/core.py | 9 ++++++--- singer_sdk/streams/graphql.py | 6 ++++-- singer_sdk/typing.py | 5 ++--- tests/core/test_jsonschema_helpers.py | 2 +- tests/samples/test_tap_sqlite.py | 2 +- 8 files changed, 25 insertions(+), 21 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3c8a18afe..95bc2bad7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,7 +43,7 @@ repos: - id: check-readthedocs - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.278 + rev: v0.0.280 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix, --show-fixes] diff --git a/singer_sdk/connectors/sql.py b/singer_sdk/connectors/sql.py index aecfbb0c1..e9a65cf80 100644 --- a/singer_sdk/connectors/sql.py +++ b/singer_sdk/connectors/sql.py @@ -179,7 +179,7 @@ def get_sqlalchemy_url(self, config: dict[str, t.Any]) -> str: @staticmethod def to_jsonschema_type( sql_type: ( - str + str # noqa: ANN401 | sqlalchemy.types.TypeEngine | type[sqlalchemy.types.TypeEngine] | t.Any diff --git a/singer_sdk/helpers/_flattening.py b/singer_sdk/helpers/_flattening.py index 29ef35cc2..02585dd80 100644 --- a/singer_sdk/helpers/_flattening.py +++ b/singer_sdk/helpers/_flattening.py @@ -252,15 +252,15 @@ def _flatten_schema( # noqa: C901 else: items.append((new_key, v)) elif len(v.values()) > 0: - if list(v.values())[0][0]["type"] == "string": - list(v.values())[0][0]["type"] = ["null", "string"] - items.append((new_key, list(v.values())[0][0])) - elif list(v.values())[0][0]["type"] == "array": - list(v.values())[0][0]["type"] = ["null", "array"] - items.append((new_key, list(v.values())[0][0])) - elif list(v.values())[0][0]["type"] == "object": - list(v.values())[0][0]["type"] = ["null", "object"] - items.append((new_key, list(v.values())[0][0])) + if next(iter(v.values()))[0]["type"] == "string": + next(iter(v.values()))[0]["type"] = ["null", "string"] + items.append((new_key, next(iter(v.values()))[0])) + elif next(iter(v.values()))[0]["type"] == "array": + next(iter(v.values()))[0]["type"] = ["null", "array"] + items.append((new_key, next(iter(v.values()))[0])) + elif next(iter(v.values()))[0]["type"] == "object": + next(iter(v.values()))[0]["type"] = ["null", "object"] + items.append((new_key, next(iter(v.values()))[0])) # Sort and check for duplicates def _key_func(item): diff --git a/singer_sdk/streams/core.py b/singer_sdk/streams/core.py index 35bc2e79e..53e9533ff 100644 --- a/singer_sdk/streams/core.py +++ b/singer_sdk/streams/core.py @@ -217,7 +217,10 @@ def is_timestamp_replication_key(self) -> bool: type_dict = self.schema.get("properties", {}).get(self.replication_key) return is_datetime_type(type_dict) - def get_starting_replication_key_value(self, context: dict | None) -> t.Any | None: + def get_starting_replication_key_value( + self, + context: dict | None, + ) -> t.Any | None: # noqa: ANN401 """Get starting replication key. Will return the value of the stream's replication key when `--state` is passed. @@ -385,7 +388,7 @@ def _write_starting_replication_value(self, context: dict | None) -> None: def get_replication_key_signpost( self, context: dict | None, # noqa: ARG002 - ) -> datetime.datetime | t.Any | None: + ) -> datetime.datetime | t.Any | None: # noqa: ANN401 """Get the replication signpost. For timestamp-based replication keys, this defaults to `utc_now()`. For @@ -1255,7 +1258,7 @@ def get_child_context(self, record: dict, context: dict | None) -> dict | None: Raises: NotImplementedError: If the stream has children but this method is not - overriden. + overridden. """ if context is None: for child_stream in self.child_streams: diff --git a/singer_sdk/streams/graphql.py b/singer_sdk/streams/graphql.py index 01e5d41ee..fde4f99b9 100644 --- a/singer_sdk/streams/graphql.py +++ b/singer_sdk/streams/graphql.py @@ -8,8 +8,10 @@ from singer_sdk.helpers._classproperty import classproperty from singer_sdk.streams.rest import RESTStream +_TToken = t.TypeVar("_TToken") -class GraphQLStream(RESTStream, metaclass=abc.ABCMeta): + +class GraphQLStream(RESTStream, t.Generic[_TToken], metaclass=abc.ABCMeta): """Abstract base class for API-type streams. GraphQL streams inherit from the class `GraphQLStream`, which in turn inherits from @@ -43,7 +45,7 @@ def query(self) -> str: def prepare_request_payload( self, context: dict | None, - next_page_token: t.Any | None, + next_page_token: _TToken | None, ) -> dict | None: """Prepare the data payload for the GraphQL API request. diff --git a/singer_sdk/typing.py b/singer_sdk/typing.py index a8f654c90..850e30e8e 100644 --- a/singer_sdk/typing.py +++ b/singer_sdk/typing.py @@ -965,9 +965,8 @@ def _jsonschema_type_check(jsonschema_type: dict, type_check: tuple[str]) -> boo for schema_type in jsonschema_type["type"]: if schema_type in type_check: return True - else: - if jsonschema_type.get("type") in type_check: # noqa: PLR5501 - return True + elif jsonschema_type.get("type") in type_check: + return True if any( _jsonschema_type_check(t, type_check) for t in jsonschema_type.get("anyOf", ()) diff --git a/tests/core/test_jsonschema_helpers.py b/tests/core/test_jsonschema_helpers.py index 3e4ba6eca..e1369dcba 100644 --- a/tests/core/test_jsonschema_helpers.py +++ b/tests/core/test_jsonschema_helpers.py @@ -490,7 +490,7 @@ def test_property_creation( property_dict = property_obj.to_dict() assert property_dict == expected_jsonschema for check_fn in TYPE_FN_CHECKS: - property_name = list(property_dict.keys())[0] + property_name = next(iter(property_dict.keys())) property_node = property_dict[property_name] if check_fn in type_fn_checks_true: assert ( diff --git a/tests/samples/test_tap_sqlite.py b/tests/samples/test_tap_sqlite.py index bceaa34b1..e2b1940da 100644 --- a/tests/samples/test_tap_sqlite.py +++ b/tests/samples/test_tap_sqlite.py @@ -48,7 +48,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"]) detected_metadata = stream.catalog_entry["metadata"] - detected_root_md = [md for md in detected_metadata if md["breadcrumb"] == []][0] + detected_root_md = next(md for md in detected_metadata if md["breadcrumb"] == []) detected_root_md = detected_root_md["metadata"] translated_metadata = StreamMetadata.from_dict(detected_root_md) assert detected_root_md["schema-name"] == translated_metadata.schema_name