Skip to content

Commit

Permalink
chore: Enable Ruff's PERF checks and apply minor refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Aug 24, 2023
1 parent f9c2dad commit 94a6181
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -265,6 +267,7 @@ select = [
"PLE", # pylint (error)
"PLR", # pylint (refactor)
"PLW", # pylint (warning)
"PERF", # perflint
"RUF", # ruff
]
src = ["samples", "singer_sdk", "tests"]
Expand Down
19 changes: 8 additions & 11 deletions singer_sdk/tap_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"]
]
8 changes: 4 additions & 4 deletions singer_sdk/testing/tap_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Check warning on line 188 in singer_sdk/testing/tap_tests.py

View check run for this annotation

Codecov / codecov/patch

singer_sdk/testing/tap_tests.py#L188

Added line #L188 was not covered by tests
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:

Check warning on line 192 in singer_sdk/testing/tap_tests.py

View check run for this annotation

Codecov / codecov/patch

singer_sdk/testing/tap_tests.py#L192

Added line #L192 was not covered by tests
raise AssertionError(error_message) from e

@classmethod
def evaluate(
Expand Down
5 changes: 4 additions & 1 deletion singer_sdk/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 94a6181

Please sign in to comment.