Skip to content

Commit 9545567

Browse files
chore: Enable Ruff UP and FA rules (#409)
1 parent a8cb2b9 commit 9545567

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ select = [
8383
"F", # Pyflakes
8484
"W", # pycodestyle warnings
8585
"E", # pycodestyle errors
86+
"FA", # flake8-future-annotations
8687
"I", # isort
8788
"N", # pep8-naming
8889
"D", # pydocsyle
8990
"ICN", # flake8-import-conventions
91+
"UP", # pyupgrade
9092
"RUF", # ruff
9193
]
9294

target_postgres/sinks.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""Postgres target sink class, which handles writing streams."""
22

3+
from __future__ import annotations
4+
35
import datetime
6+
import typing as t
47
import uuid
5-
from typing import Any, Dict, Iterable, List, Optional, Sequence, Union, cast
68

79
import sqlalchemy as sa
810
from singer_sdk.sinks import SQLSink
@@ -39,7 +41,7 @@ def connector(self) -> PostgresConnector:
3941
Returns:
4042
The connector object.
4143
"""
42-
return cast(PostgresConnector, self._connector)
44+
return t.cast(PostgresConnector, self._connector)
4345

4446
def setup(self) -> None:
4547
"""Set up Sink.
@@ -120,10 +122,10 @@ def bulk_insert_records( # type: ignore[override]
120122
self,
121123
table: sa.Table,
122124
schema: dict,
123-
records: Iterable[Dict[str, Any]],
124-
primary_keys: Sequence[str],
125+
records: t.Iterable[dict[str, t.Any]],
126+
primary_keys: t.Sequence[str],
125127
connection: sa.engine.Connection,
126-
) -> Optional[int]:
128+
) -> int | None:
127129
"""Bulk insert records to an existing destination table.
128130
129131
The default implementation uses a generic SQLAlchemy bulk insert operation.
@@ -142,7 +144,7 @@ def bulk_insert_records( # type: ignore[override]
142144
True if table exists, False if not, None if unsure or undetectable.
143145
"""
144146
columns = self.column_representation(schema)
145-
insert: str = cast(
147+
insert: str = t.cast(
146148
str,
147149
self.generate_insert_statement(
148150
table.name,
@@ -151,10 +153,10 @@ def bulk_insert_records( # type: ignore[override]
151153
)
152154
self.logger.info("Inserting with SQL: %s", insert)
153155
# Only one record per PK, we want to take the last one
154-
data_to_insert: List[Dict[str, Any]] = []
156+
data_to_insert: list[dict[str, t.Any]] = []
155157

156158
if self.append_only is False:
157-
insert_records: Dict[str, Dict] = {} # pk : record
159+
insert_records: dict[str, dict] = {} # pk : record
158160
for record in records:
159161
insert_record = {}
160162
for column in columns:
@@ -178,9 +180,9 @@ def upsert(
178180
from_table: sa.Table,
179181
to_table: sa.Table,
180182
schema: dict,
181-
join_keys: Sequence[str],
183+
join_keys: t.Sequence[str],
182184
connection: sa.engine.Connection,
183-
) -> Optional[int]:
185+
) -> int | None:
184186
"""Merge upsert data from one table to another.
185187
186188
Args:
@@ -247,7 +249,7 @@ def upsert(
247249
def column_representation(
248250
self,
249251
schema: dict,
250-
) -> List[sa.Column]:
252+
) -> list[sa.Column]:
251253
"""Return a sqlalchemy table representation for the current schema."""
252254
columns: list[sa.Column] = []
253255
for property_name, property_jsonschema in schema["properties"].items():
@@ -262,8 +264,8 @@ def column_representation(
262264
def generate_insert_statement(
263265
self,
264266
full_table_name: str,
265-
columns: List[sa.Column], # type: ignore[override]
266-
) -> Union[str, Executable]:
267+
columns: list[sa.Column], # type: ignore[override]
268+
) -> str | Executable:
267269
"""Generate an insert statement for the given records.
268270
269271
Args:
@@ -277,12 +279,12 @@ def generate_insert_statement(
277279
table = sa.Table(full_table_name, metadata, *columns)
278280
return sa.insert(table)
279281

280-
def conform_name(self, name: str, object_type: Optional[str] = None) -> str:
282+
def conform_name(self, name: str, object_type: str | None = None) -> str:
281283
"""Conforming names of tables, schemas, column names."""
282284
return name
283285

284286
@property
285-
def schema_name(self) -> Optional[str]:
287+
def schema_name(self) -> str | None:
286288
"""Return the schema name or `None` if using names with no schema part.
287289
288290
Note that after the next SDK release (after 0.14.0) we can remove this

target_postgres/tests/samples/sample_tap_countries/countries_tap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- https://countries.trevorblades.com/
77
"""
88

9-
from typing import List
9+
from __future__ import annotations
1010

1111
from singer_sdk import Stream, Tap
1212
from singer_sdk.typing import PropertiesList
@@ -23,7 +23,7 @@ class SampleTapCountries(Tap):
2323
name: str = "sample-tap-countries"
2424
config_jsonschema = PropertiesList().to_dict()
2525

26-
def discover_streams(self) -> List[Stream]:
26+
def discover_streams(self) -> list[Stream]:
2727
"""Return a list of discovered streams."""
2828
return [
2929
CountriesStream(tap=self),

0 commit comments

Comments
 (0)