From 94a6181120013e03fb66750329a8bde9b560c5da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Thu, 24 Aug 2023 16:30:50 -0600 Subject: [PATCH] chore: Enable Ruff's PERF checks and apply minor refactorings --- pyproject.toml | 5 ++++- singer_sdk/tap_base.py | 19 ++++++++----------- singer_sdk/testing/tap_tests.py | 8 ++++---- singer_sdk/typing.py | 5 ++++- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 851eee3dc..ea5884d67 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -243,7 +243,8 @@ select = [ "C4", # flake8-comprehensions "DTZ", # flake8-datetimezs "T10", # flake8-debugger - "EM", # flake8-error-message + "EM", # flake8-errmsg + "FA", # flake8-future-annotations "ISC", # flake8-implicit-str-concat "ICN", # flake8-import-conventions "G", # flake8-logging-format @@ -254,6 +255,7 @@ select = [ "Q", # flake8-quotes "RSE", # flake8-raise "RET", # flake8-return + # "SLF", # flake8-self "SIM", # flake8-simplify "TID", # flake8-tidy-imports "TCH", # flake8-type-checking @@ -265,6 +267,7 @@ select = [ "PLE", # pylint (error) "PLR", # pylint (refactor) "PLW", # pylint (warning) + "PERF", # perflint "RUF", # ruff ] src = ["samples", "singer_sdk", "tests"] diff --git a/singer_sdk/tap_base.py b/singer_sdk/tap_base.py index 8b025a1f8..d4b5a8dc3 100644 --- a/singer_sdk/tap_base.py +++ b/singer_sdk/tap_base.py @@ -408,7 +408,7 @@ def load_state(self, state: dict[str, t.Any]) -> None: def _reset_state_progress_markers(self) -> None: """Clear prior jobs' progress markers at beginning of sync.""" - for _, state in self.state.get("bookmarks", {}).items(): + for state in self.state.get("bookmarks", {}).values(): _state.reset_state_progress_markers(state) for partition_state in state.get("partitions", []): _state.reset_state_progress_markers(partition_state) @@ -667,14 +667,11 @@ def discover_streams(self) -> list[Stream]: Returns: List of discovered Stream objects. """ - result: list[Stream] = [] - for catalog_entry in self.catalog_dict["streams"]: - result.append( - self.default_stream_class( - tap=self, - catalog_entry=catalog_entry, - connector=self.tap_connector, - ), + return [ + self.default_stream_class( + tap=self, + catalog_entry=catalog_entry, + connector=self.tap_connector, ) - - return result + for catalog_entry in self.catalog_dict["streams"] + ] diff --git a/singer_sdk/testing/tap_tests.py b/singer_sdk/testing/tap_tests.py index a95720d57..ecb7eb811 100644 --- a/singer_sdk/testing/tap_tests.py +++ b/singer_sdk/testing/tap_tests.py @@ -185,12 +185,12 @@ def test(self) -> None: Raises: AssertionError: if value cannot be parsed as a datetime. """ - for v in self.non_null_attribute_values: - try: + try: + for v in self.non_null_attribute_values: error_message = f"Unable to parse value ('{v}') with datetime parser." assert parser.parse(v), error_message - except parser.ParserError as e: - raise AssertionError(error_message) from e + except parser.ParserError as e: + raise AssertionError(error_message) from e @classmethod def evaluate( diff --git a/singer_sdk/typing.py b/singer_sdk/typing.py index 850e30e8e..fd17b9d3d 100644 --- a/singer_sdk/typing.py +++ b/singer_sdk/typing.py @@ -58,7 +58,10 @@ import typing as t import sqlalchemy -from jsonschema import ValidationError, Validator, validators +from jsonschema import ValidationError, validators + +if t.TYPE_CHECKING: + from jsonschema.protocols import Validator from singer_sdk.helpers._typing import ( JSONSCHEMA_ANNOTATION_SECRET,