Skip to content

Commit

Permalink
chore: Bump Ruff to 0.8.1 and apply TC006 (runtime-cast-value)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Nov 30, 2024
1 parent 7fd95e3 commit cd89aff
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.4
rev: 0.30.0
hooks:
- id: check-dependabot
- id: check-github-workflows
- id: check-readthedocs

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.0
rev: v0.8.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
Expand Down
5 changes: 3 additions & 2 deletions samples/sample_tap_gitlab/gitlab_rest_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def partitions(self) -> list[dict]:
if "{project_id}" in self.path:
return [
{"project_id": pid}
for pid in t.cast(list, self.config.get("project_ids"))
for pid in t.cast("list", self.config.get("project_ids"))
]
if "{group_id}" in self.path:
if "group_ids" not in self.config:
Expand All @@ -84,7 +84,8 @@ def partitions(self) -> list[dict]:
)
raise ValueError(msg)
return [
{"group_id": gid} for gid in t.cast(list, self.config.get("group_ids"))
{"group_id": gid}
for gid in t.cast("list", self.config.get("group_ids"))
]
msg = (
f"Could not detect partition type for Gitlab stream '{self.name}' "
Expand Down
4 changes: 2 additions & 2 deletions singer_sdk/connectors/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ def get_sqlalchemy_url(self, config: dict[str, t.Any]) -> str: # noqa: PLR6301
msg = "Could not find or create 'sqlalchemy_url' for connection."
raise ConfigValidationError(msg)

return t.cast(str, config["sqlalchemy_url"])
return t.cast("str", config["sqlalchemy_url"])

def to_jsonschema_type(
self,
Expand Down Expand Up @@ -1429,7 +1429,7 @@ def _get_type_sort_key(

_len = int(getattr(sql_type, "length", 0) or 0)

_pytype = t.cast(type, sql_type.python_type)
_pytype = t.cast("type", sql_type.python_type)
if issubclass(_pytype, (str, bytes)):
return 900, _len
if issubclass(_pytype, datetime):
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/helpers/_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_writeable_state_dict(
tap_state["bookmarks"] = {}
if tap_stream_id not in tap_state["bookmarks"]:
tap_state["bookmarks"][tap_stream_id] = {}
stream_state = t.cast(dict, tap_state["bookmarks"][tap_stream_id])
stream_state = t.cast("dict", tap_state["bookmarks"][tap_stream_id])
if not state_partition_context:
return stream_state

Expand Down
4 changes: 2 additions & 2 deletions singer_sdk/helpers/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ def get_datelike_property_type(property_schema: dict) -> str | None:
Otherwise return None.
"""
if _is_string_with_format(property_schema):
return t.cast(str, property_schema["format"])
return t.cast("str", property_schema["format"])
if "anyOf" in property_schema:
for type_dict in property_schema["anyOf"]:
if _is_string_with_format(type_dict):
return t.cast(str, type_dict["format"])
return t.cast("str", type_dict["format"])
return None


Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/plugin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def config(self) -> t.Mapping[str, t.Any]:
Returns:
A frozen (read-only) config dictionary map.
"""
return t.cast(dict, MappingProxyType(self._config))
return t.cast("dict", MappingProxyType(self._config))

@staticmethod
def _is_secret_config(config_key: str) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/tap_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def catalog_dict(self) -> dict:
Returns:
The tap's catalog as a dict
"""
return t.cast(dict, self._singer_catalog.to_dict())
return t.cast("dict", self._singer_catalog.to_dict())

@property
def catalog_json_text(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/testing/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def _select_all(catalog_dict: dict) -> dict:
for catalog_entry in catalog.streams:
catalog_entry.metadata.root.selected = True

return t.cast(dict, catalog.to_dict())
return t.cast("dict", catalog.to_dict())


def target_sync_test(
Expand Down
8 changes: 4 additions & 4 deletions singer_sdk/testing/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from collections import defaultdict
from contextlib import redirect_stderr, redirect_stdout

from singer_sdk import Tap, Target
from singer_sdk.testing.config import SuiteConfig

if t.TYPE_CHECKING:
from pathlib import Path

from singer_sdk import Tap, Target
from singer_sdk.helpers._compat import Traversable


Expand Down Expand Up @@ -115,7 +115,7 @@ def new_tap(self) -> Tap:
Returns:
A configured Tap instance.
"""
return t.cast(Tap, self.create())
return t.cast("Tap", self.create())

def run_discovery(self) -> str:
"""Run tap discovery.
Expand Down Expand Up @@ -233,7 +233,7 @@ def new_target(self) -> Target:
Returns:
A configured Target instance.
"""
return t.cast(Target, self.create())
return t.cast("Target", self.create())

@property
def target_input(self) -> t.IO[str]:
Expand All @@ -247,7 +247,7 @@ def target_input(self) -> t.IO[str]:
self._input = self.input_io
elif self.input_filepath:
self._input = self.input_filepath.open(encoding="utf8")
return t.cast(t.IO[str], self._input)
return t.cast("t.IO[str]", self._input)

@target_input.setter
def target_input(self, value: t.IO[str]) -> None:
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/testing/tap_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test(self) -> None:
catalog = tap1.catalog_dict
# Reset and re-initialize with discovered catalog
kwargs = {k: v for k, v in self.runner.default_kwargs.items() if k != "catalog"}
tap2: Tap = t.cast(type[Tap], self.runner.singer_class)(
tap2: Tap = t.cast("type[Tap]", self.runner.singer_class)(
config=self.runner.config,
catalog=catalog,
**kwargs,
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ def type_dict(self) -> dict: # type: ignore[override]
# TODO: this should be a TypeError, but it's a breaking change.
raise ValueError(msg) # noqa: TRY004

return t.cast(dict, wrapped.type_dict)
return t.cast("dict", wrapped.type_dict)

def to_dict(self) -> dict:
"""Return a dict mapping the property name to its definition.
Expand Down
8 changes: 4 additions & 4 deletions tests/samples/test_tap_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from samples.sample_tap_sqlite import SQLiteTap
from samples.sample_target_csv.csv_target import SampleTargetCSV
from singer_sdk import SQLStream
from singer_sdk._singerlib import MetadataMapping, StreamMetadata
from singer_sdk.testing import (
get_standard_tap_tests,
Expand All @@ -21,6 +20,7 @@
if t.TYPE_CHECKING:
from pathlib import Path

from singer_sdk import SQLStream
from singer_sdk.tap_base import SQLTap


Expand Down Expand Up @@ -50,7 +50,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"])
stream = t.cast("SQLStream", sqlite_sample_tap.streams["main-t1"])
detected_metadata = stream.catalog_entry["metadata"]
detected_root_md = next(md for md in detected_metadata if md["breadcrumb"] == [])
detected_root_md = detected_root_md["metadata"]
Expand All @@ -68,7 +68,7 @@ def test_sql_metadata(sqlite_sample_tap: SQLTap):
def test_sqlite_discovery(sqlite_sample_tap: SQLTap):
_discover_and_select_all(sqlite_sample_tap)
sqlite_sample_tap.sync_all()
stream = t.cast(SQLStream, sqlite_sample_tap.streams["main-t1"])
stream = t.cast("SQLStream", sqlite_sample_tap.streams["main-t1"])
schema = stream.schema
assert len(schema["properties"]) == 3
assert stream.name == stream.tap_stream_id == "main-t1"
Expand All @@ -89,7 +89,7 @@ def test_sqlite_discovery(sqlite_sample_tap: SQLTap):

def test_sqlite_input_catalog(sqlite_sample_tap: SQLTap):
sqlite_sample_tap.sync_all()
stream = t.cast(SQLStream, sqlite_sample_tap.streams["main-t1"])
stream = t.cast("SQLStream", sqlite_sample_tap.streams["main-t1"])
assert len(stream.schema["properties"]) == 3
assert len(stream.stream_maps[0].transformed_schema["properties"]) == 3

Expand Down

0 comments on commit cd89aff

Please sign in to comment.