Skip to content

Commit

Permalink
Merge branch 'main' into 1046-feat-faster-json-dumps-with-msgspec
Browse files Browse the repository at this point in the history
  • Loading branch information
BuzzCutNorman authored Jul 26, 2023
2 parents 60e2e36 + 019902e commit 24ee6cd
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/connectors/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions singer_sdk/helpers/_flattening.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 6 additions & 3 deletions singer_sdk/streams/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions singer_sdk/streams/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions singer_sdk/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", ())
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_jsonschema_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion tests/samples/test_tap_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 24ee6cd

Please sign in to comment.