Skip to content

Commit 6b46c9b

Browse files
authored
Chore: Update ruff rules and fix exceptions (#205)
1 parent 3702e71 commit 6b46c9b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+671
-434
lines changed

airbyte/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@
66
## API Reference
77
88
"""
9+
910
from __future__ import annotations
1011

11-
from airbyte import caches, cloud, datasets, documents, exceptions, results, secrets, sources
12+
from airbyte import (
13+
caches,
14+
cloud,
15+
datasets,
16+
documents,
17+
exceptions, # noqa: ICN001 # No 'exc' alias for top-level module
18+
results,
19+
secrets,
20+
sources,
21+
)
1222
from airbyte.caches.bigquery import BigQueryCache
1323
from airbyte.caches.duckdb import DuckDBCache
1424
from airbyte.caches.util import get_default_cache, new_local_cache

airbyte/_executor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def _stream_from_file(file: IO[str]) -> Generator[str, Any, None]:
124124
exit_code = process.wait()
125125

126126
# If the exit code is not 0 or -15 (SIGTERM), raise an exception
127-
if exit_code not in (0, -15):
127+
if exit_code not in {0, -15}:
128128
raise exc.AirbyteSubprocessFailedError(
129129
run_args=args,
130130
exit_code=exit_code,

airbyte/_processors/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
2+
"""Internal processors for PyAirbyte."""
3+
4+
from __future__ import annotations

airbyte/_processors/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def process_airbyte_messages(
185185

186186
elif message.type is Type.STATE:
187187
state_msg = cast(AirbyteStateMessage, message.state)
188-
if state_msg.type in [AirbyteStateType.GLOBAL, AirbyteStateType.LEGACY]:
188+
if state_msg.type in {AirbyteStateType.GLOBAL, AirbyteStateType.LEGACY}:
189189
self._pending_state_messages[f"_{state_msg.type}"].append(state_msg)
190190
else:
191191
stream_state = cast(AirbyteStreamState, state_msg.stream)

airbyte/_processors/sql/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def __init__(
104104
self._ensure_schema_exists()
105105
self._catalog_manager = CatalogManager(
106106
engine=self.get_sql_engine(),
107-
table_name_resolver=lambda stream_name: self.get_sql_table_name(stream_name),
107+
table_name_resolver=self.get_sql_table_name,
108108
)
109109
self.file_writer = file_writer or self.file_writer_class(cache)
110110
self.type_converter = self.type_converter_class()
@@ -550,7 +550,7 @@ def write_stream_data(
550550
for batch_handle in batches_to_finalize:
551551
files += batch_handle.files
552552
# Use the max batch ID as the batch ID for table names.
553-
max_batch_id = max([batch.batch_id for batch in batches_to_finalize])
553+
max_batch_id = max(batch.batch_id for batch in batches_to_finalize)
554554

555555
temp_table_name = self._write_files_to_new_table(
556556
files=files,
@@ -820,7 +820,7 @@ def _get_primary_keys(
820820
joined_pks = [".".join(pk) for pk in pks]
821821
for pk in joined_pks:
822822
if "." in pk:
823-
msg = "Nested primary keys are not yet supported. Found: {pk}"
823+
msg = f"Nested primary keys are not yet supported. Found: {pk}"
824824
raise NotImplementedError(msg)
825825

826826
return joined_pks

airbyte/_processors/sql/duckdb.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,6 @@ def _setup(self) -> None:
4646

4747
Path(self.cache.db_path).parent.mkdir(parents=True, exist_ok=True)
4848

49-
@overrides
50-
def _ensure_compatible_table_schema(
51-
self,
52-
stream_name: str,
53-
*,
54-
raise_on_error: bool = True,
55-
) -> bool:
56-
"""Return true if the given table is compatible with the stream's schema.
57-
58-
In addition to the base implementation, this also checks primary keys.
59-
"""
60-
# call super
61-
if not super()._ensure_compatible_table_schema(
62-
stream_name=stream_name,
63-
raise_on_error=raise_on_error,
64-
):
65-
return False
66-
67-
# TODO: Add validation for primary keys after DuckDB adds support for primary key
68-
# inspection: https://github.com/Mause/duckdb_engine/issues/594
69-
70-
return True
71-
7249
def _write_files_to_new_table(
7350
self,
7451
files: list[Path],

airbyte/_util/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Note: This module is for internal use only and it should not be depended upon for production use.
55
It is subject to change without notice.
66
"""
7+
78
from __future__ import annotations
89

910
from airbyte._util.pip_util import connector_pip_url, github_pip_url

airbyte/_util/document_rendering.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
22
"""Methods for converting Airbyte records into documents."""
3+
34
from __future__ import annotations
45

56
from typing import TYPE_CHECKING, Any, Optional

airbyte/_util/meta.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
This module contains functions for detecting environment and runtime information.
55
"""
6+
67
from __future__ import annotations
78

89
import os
@@ -61,10 +62,7 @@ def is_interactive() -> bool:
6162
if is_ci():
6263
return False
6364

64-
if sys.__stdin__.isatty() and sys.__stdout__.isatty():
65-
return True
66-
67-
return False
65+
return bool(sys.__stdin__.isatty() and sys.__stdout__.isatty())
6866

6967

7068
@lru_cache
@@ -105,7 +103,7 @@ def get_notebook_name() -> str | None:
105103
@lru_cache
106104
def get_vscode_notebook_name() -> str | None:
107105
with suppress(Exception):
108-
import IPython
106+
import IPython # noqa: PLC0415
109107

110108
return Path(
111109
IPython.extract_module_locals()[1]["__vsc_ipynb_file__"],

airbyte/_util/telemetry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- Flags to help us understand if PyAirbyte is running on CI, Google Colab, or another environment.
2929
3030
"""
31+
3132
from __future__ import annotations
3233

3334
import datetime

0 commit comments

Comments
 (0)