From 131d7015d57411ce5919040fb4ed22883f42aad0 Mon Sep 17 00:00:00 2001 From: "Edgar R. M" Date: Thu, 30 Mar 2023 13:07:16 -0600 Subject: [PATCH] chore: Enable `RUF` Ruff checks (#1566) --- pyproject.toml | 1 + samples/sample_tap_google_analytics/ga_tap_stream.py | 10 ---------- singer_sdk/connectors/sql.py | 2 +- singer_sdk/helpers/_catalog.py | 8 +++++--- singer_sdk/helpers/_flattening.py | 6 +++--- singer_sdk/helpers/_typing.py | 4 ++-- singer_sdk/streams/rest.py | 2 +- singer_sdk/testing/runners.py | 2 +- tests/core/test_capabilities.py | 4 ++-- tests/core/test_connector_sql.py | 2 +- 10 files changed, 17 insertions(+), 24 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index de12656b0..6529aeb8c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -254,6 +254,7 @@ select = [ "PTH", # flake8-use-pathlib "ERA", # eradicate "PGH", # pygrep-hooks + "RUF", # ruff ] src = ["samples", "singer_sdk", "tests"] target-version = "py37" diff --git a/samples/sample_tap_google_analytics/ga_tap_stream.py b/samples/sample_tap_google_analytics/ga_tap_stream.py index 14844a345..0a99a7fc9 100644 --- a/samples/sample_tap_google_analytics/ga_tap_stream.py +++ b/samples/sample_tap_google_analytics/ga_tap_stream.py @@ -54,16 +54,6 @@ def prepare_request_payload( "viewId": self.config["view_id"], "metrics": [{"expression": m} for m in self.metrics], "dimensions": [{"name": d} for d in self.dimensions], - # "orderBys": [ - # { # noqa: ERA001 - # "fieldName": "ga:sessions", # noqa: ERA001 - # "sortOrder": "DESCENDING", # noqa: ERA001 - # }, - # { # noqa: ERA001 - # "fieldName": "ga:pageviews", # noqa: ERA001 - # "sortOrder": "DESCENDING", # noqa: ERA001 - # }, - # ], } if self.config.get("start_date"): request_def["dateRanges"] = [ diff --git a/singer_sdk/connectors/sql.py b/singer_sdk/connectors/sql.py index 1a307e6cb..5b9ee2dfd 100644 --- a/singer_sdk/connectors/sql.py +++ b/singer_sdk/connectors/sql.py @@ -451,7 +451,7 @@ def discover_catalog_entry( # a replication_key value. # - 'LOG_BASED' replication must be enabled by the developer, according # to source-specific implementation capabilities. - replication_method = next(reversed(["FULL_TABLE"] + addl_replication_methods)) + replication_method = next(reversed(["FULL_TABLE", *addl_replication_methods])) # Create the catalog entry object return CatalogEntry( diff --git a/singer_sdk/helpers/_catalog.py b/singer_sdk/helpers/_catalog.py index cc91ff42b..2aaffe543 100644 --- a/singer_sdk/helpers/_catalog.py +++ b/singer_sdk/helpers/_catalog.py @@ -57,8 +57,10 @@ def _pop_deselected_schema( return for property_name, property_def in list(schema_at_breadcrumb["properties"].items()): - property_breadcrumb: tuple[str, ...] = tuple( - list(breadcrumb) + ["properties", property_name], + property_breadcrumb: tuple[str, ...] = ( + *breadcrumb, + "properties", + property_name, ) selected = mask[property_breadcrumb] if not selected: @@ -89,7 +91,7 @@ def pop_deselected_record_properties( updating in place. """ for property_name, val in list(record.items()): - property_breadcrumb = breadcrumb + ("properties", property_name) + property_breadcrumb = (*breadcrumb, "properties", property_name) selected = mask[property_breadcrumb] if not selected: record.pop(property_name) diff --git a/singer_sdk/helpers/_flattening.py b/singer_sdk/helpers/_flattening.py index 5cd81a706..b9a47ef09 100644 --- a/singer_sdk/helpers/_flattening.py +++ b/singer_sdk/helpers/_flattening.py @@ -56,7 +56,7 @@ def flatten_key(key_name: str, parent_keys: list[str], separator: str = "__") -> >>> flatten_key("foo", ["bar", "baz"], separator=".") 'bar.baz.foo' """ - full_key = parent_keys + [key_name] + full_key = [*parent_keys, key_name] inflected_key = full_key.copy() reducer_index = 0 while len(separator.join(inflected_key)) >= 255 and reducer_index < len( @@ -241,7 +241,7 @@ def _flatten_schema( items.extend( _flatten_schema( v, - parent_keys + [k], + [*parent_keys, k], separator=separator, level=level + 1, max_level=max_level, @@ -334,7 +334,7 @@ def _flatten_record( _flatten_record( v, flattened_schema, - parent_key + [k], + [*parent_key, k], separator=separator, level=level + 1, max_level=max_level, diff --git a/singer_sdk/helpers/_typing.py b/singer_sdk/helpers/_typing.py index ad0de377d..8b2375f00 100644 --- a/singer_sdk/helpers/_typing.py +++ b/singer_sdk/helpers/_typing.py @@ -343,7 +343,7 @@ class TypeConformanceLevel(Enum): """ -def conform_record_data_types( # noqa: C901 +def conform_record_data_types( stream_name: str, record: dict[str, Any], schema: dict, @@ -368,7 +368,7 @@ def _conform_record_data_types( schema: dict, level: TypeConformanceLevel, parent: str | None, -) -> tuple[dict[str, Any], list[str]]: # noqa: C901 +) -> tuple[dict[str, Any], list[str]]: """Translate values in record dictionary to singer-compatible data types. Any property names not found in the schema catalog will be removed, and a single diff --git a/singer_sdk/streams/rest.py b/singer_sdk/streams/rest.py index 5bee7cd84..a0e3b1b6b 100644 --- a/singer_sdk/streams/rest.py +++ b/singer_sdk/streams/rest.py @@ -371,7 +371,7 @@ def request_records(self, context: dict | None) -> Iterable[dict]: def _write_request_duration_log( self, - endpoint: str, # noqa: ARG002 + endpoint: str, response: requests.Response, context: dict | None, extra_tags: dict | None, diff --git a/singer_sdk/testing/runners.py b/singer_sdk/testing/runners.py index 6c5596964..c83a3f31f 100644 --- a/singer_sdk/testing/runners.py +++ b/singer_sdk/testing/runners.py @@ -231,7 +231,7 @@ def target_input(self) -> IO[str]: if self.input_io: self._input = self.input_io elif self.input_filepath: - self._input = Path(self.input_filepath).open() # noqa: SIM115 + self._input = Path(self.input_filepath).open() return cast(IO[str], self._input) @target_input.setter diff --git a/tests/core/test_capabilities.py b/tests/core/test_capabilities.py index e74259dbf..49149469a 100644 --- a/tests/core/test_capabilities.py +++ b/tests/core/test_capabilities.py @@ -18,13 +18,13 @@ class DummyCapabilitiesEnum(CapabilitiesEnum): def test_deprecated_capabilities(): with warnings.catch_warnings(): warnings.simplefilter("error") - DummyCapabilitiesEnum.MY_SUPPORTED_FEATURE + _ = DummyCapabilitiesEnum.MY_SUPPORTED_FEATURE with pytest.warns( DeprecationWarning, match="is deprecated. No longer supported", ) as record: - DummyCapabilitiesEnum.MY_DEPRECATED_FEATURE + _ = DummyCapabilitiesEnum.MY_DEPRECATED_FEATURE warning = record.list[0] frameinfo = getframeinfo(currentframe()) diff --git a/tests/core/test_connector_sql.py b/tests/core/test_connector_sql.py index dc16264e1..1c04dbcdd 100644 --- a/tests/core/test_connector_sql.py +++ b/tests/core/test_connector_sql.py @@ -154,7 +154,7 @@ def test_deprecated_functions_warn(self, connector): with pytest.deprecated_call(): connector.create_sqlalchemy_connection() with pytest.deprecated_call(): - connector.connection + _ = connector.connection def test_connect_calls_engine(self, connector): with mock.patch.object(