Skip to content

Commit c347760

Browse files
authored
chore: make full CDK codebase compliant with mypy (#105)
1 parent ac6cf92 commit c347760

File tree

80 files changed

+599
-435
lines changed

Some content is hidden

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

80 files changed

+599
-435
lines changed

.github/dependabot.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ updates:
1313
interval: daily
1414
labels:
1515
- chore
16-
open-pull-requests-limit: 8 # default is 5
16+
open-pull-requests-limit: 8 # default is 5
1717

1818
- package-ecosystem: github-actions
19-
open-pull-requests-limit: 5 # default is 5
19+
open-pull-requests-limit: 5 # default is 5
2020
directory: "/"
2121
commit-message:
2222
prefix: "ci(deps): "
@@ -29,5 +29,5 @@ updates:
2929
minor-and-patch:
3030
applies-to: version-updates
3131
update-types:
32-
- patch
33-
- minor
32+
- patch
33+
- minor

.github/workflows/connector-tests.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ jobs:
7272
cdk_extra: n/a
7373
- connector: source-shopify
7474
cdk_extra: n/a
75-
- connector: source-chargebee
76-
cdk_extra: n/a
77-
- connector: source-s3
78-
cdk_extra: file-based
79-
- connector: destination-pinecone
80-
cdk_extra: vector-db-based
75+
# Chargebee is being flaky:
76+
# - connector: source-chargebee
77+
# cdk_extra: n/a
78+
# These two are behind in CDK updates and can't be used as tests until they are updated:
79+
# - connector: source-s3
80+
# cdk_extra: file-based
81+
# - connector: destination-pinecone
82+
# cdk_extra: vector-db-based
8183
- connector: destination-motherduck
8284
cdk_extra: sql
8385
# ZenDesk currently failing (as of 2024-12-02)
@@ -91,7 +93,7 @@ jobs:
9193
# - connector: source-pokeapi
9294
# cdk_extra: n/a
9395

94-
name: "Check: '${{matrix.connector}}' (skip=${{needs.cdk_changes.outputs[matrix.cdk_extra] == 'false'}})"
96+
name: "Check: '${{matrix.connector}}' (skip=${{needs.cdk_changes.outputs['src'] == 'false' || needs.cdk_changes.outputs[matrix.cdk_extra] == 'false'}})"
9597
steps:
9698
- name: Abort if extra not changed (${{matrix.cdk_extra}})
9799
id: no_changes

.github/workflows/publish_sdm_connector.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ on:
88
workflow_dispatch:
99
inputs:
1010
version:
11-
description:
12-
The version to publish, ie 1.0.0 or 1.0.0-dev1.
13-
If omitted, and if run from a release branch, the version will be
14-
inferred from the git tag.
15-
If omitted, and if run from a non-release branch, then only a SHA-based
16-
Docker tag will be created.
11+
description: The version to publish, ie 1.0.0 or 1.0.0-dev1.
12+
If omitted, and if run from a release branch, the version will be
13+
inferred from the git tag.
14+
If omitted, and if run from a non-release branch, then only a SHA-based
15+
Docker tag will be created.
1716
required: false
1817
dry_run:
1918
description: If true, the workflow will not push to DockerHub.
@@ -25,7 +24,6 @@ jobs:
2524
build:
2625
runs-on: ubuntu-latest
2726
steps:
28-
2927
- name: Detect Release Tag Version
3028
if: startsWith(github.ref, 'refs/tags/v')
3129
run: |
@@ -168,7 +166,6 @@ jobs:
168166
tags: |
169167
airbyte/source-declarative-manifest:${{ env.VERSION }}
170168
171-
172169
- name: Build and push ('latest' tag)
173170
# Only run if version is set and IS_PRERELEASE is false
174171
if: env.VERSION != '' && env.IS_PRERELEASE == 'false' && github.event.inputs.dry_run == 'false'

.github/workflows/pytest_matrix.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ on:
1212
branches:
1313
- main
1414
paths:
15-
- 'airbyte_cdk/**'
16-
- 'unit_tests/**'
17-
- 'poetry.lock'
18-
- 'pyproject.toml'
15+
- "airbyte_cdk/**"
16+
- "unit_tests/**"
17+
- "poetry.lock"
18+
- "pyproject.toml"
1919
pull_request:
2020

2121
jobs:

.github/workflows/python_lint.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,7 @@ jobs:
7272
- name: Install dependencies
7373
run: poetry install --all-extras
7474

75-
# Job-specifc step(s):
75+
# Job-specific step(s):
7676

77-
# For now, we run mypy only on modified files
78-
- name: Get changed Python files
79-
id: changed-py-files
80-
uses: tj-actions/changed-files@v43
81-
with:
82-
files: "airbyte_cdk/**/*.py"
83-
- name: Run mypy on changed files
84-
if: steps.changed-py-files.outputs.any_changed == 'true'
85-
run: poetry run mypy ${{ steps.changed-py-files.outputs.all_changed_files }} --config-file mypy.ini --install-types --non-interactive
77+
- name: Run mypy
78+
run: poetry run mypy --config-file mypy.ini airbyte_cdk

airbyte_cdk/cli/source_declarative_manifest/_run.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from pathlib import Path
2626
from typing import Any, cast
2727

28-
from orjson import orjson
28+
import orjson
2929

3030
from airbyte_cdk.entrypoint import AirbyteEntrypoint, launch
3131
from airbyte_cdk.models import (
@@ -72,7 +72,7 @@ def __init__(
7272
super().__init__(
7373
catalog=catalog,
7474
config=config,
75-
state=state,
75+
state=state, # type: ignore [arg-type]
7676
path_to_yaml="manifest.yaml",
7777
)
7878

@@ -152,18 +152,24 @@ def handle_remote_manifest_command(args: list[str]) -> None:
152152
)
153153

154154

155-
def create_declarative_source(args: list[str]) -> ConcurrentDeclarativeSource:
155+
def create_declarative_source(
156+
args: list[str],
157+
) -> ConcurrentDeclarativeSource: # type: ignore [type-arg]
156158
"""Creates the source with the injected config.
157159
158160
This essentially does what other low-code sources do at build time, but at runtime,
159161
with a user-provided manifest in the config. This better reflects what happens in the
160162
connector builder.
161163
"""
162164
try:
165+
config: Mapping[str, Any] | None
166+
catalog: ConfiguredAirbyteCatalog | None
167+
state: list[AirbyteStateMessage]
163168
config, catalog, state = _parse_inputs_into_config_catalog_state(args)
164-
if "__injected_declarative_manifest" not in config:
169+
if config is None or "__injected_declarative_manifest" not in config:
165170
raise ValueError(
166-
f"Invalid config: `__injected_declarative_manifest` should be provided at the root of the config but config only has keys {list(config.keys())}"
171+
"Invalid config: `__injected_declarative_manifest` should be provided at the root "
172+
f"of the config but config only has keys: {list(config.keys() if config else [])}"
167173
)
168174
return ConcurrentDeclarativeSource(
169175
config=config,

airbyte_cdk/config_observation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from copy import copy
1111
from typing import Any, List, MutableMapping
1212

13-
from orjson import orjson
13+
import orjson
1414

1515
from airbyte_cdk.models import (
1616
AirbyteControlConnectorConfigMessage,

airbyte_cdk/connector_builder/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sys
77
from typing import Any, List, Mapping, Optional, Tuple
88

9-
from orjson import orjson
9+
import orjson
1010

1111
from airbyte_cdk.connector import BaseConnector
1212
from airbyte_cdk.connector_builder.connector_builder_handler import (

airbyte_cdk/connector_builder/message_grouper.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def _cursor_field_to_nested_and_composite_field(
7171

7272
is_nested_key = isinstance(field[0], str)
7373
if is_nested_key:
74-
return [field] # type: ignore # the type of field is expected to be List[str] here
74+
return [field]
7575

7676
raise ValueError(f"Unknown type for cursor field `{field}")
7777

@@ -232,9 +232,9 @@ def _get_message_groups(
232232
current_slice_descriptor = self._parse_slice_description(message.log.message) # type: ignore[union-attr] # AirbyteMessage with MessageType.LOG has log.message
233233
current_slice_pages = []
234234
at_least_one_page_in_group = False
235-
elif message.type == MessageType.LOG and message.log.message.startswith(
235+
elif message.type == MessageType.LOG and message.log.message.startswith( # type: ignore[union-attr] # None doesn't have 'message'
236236
SliceLogger.SLICE_LOG_PREFIX
237-
): # type: ignore[union-attr] # AirbyteMessage with MessageType.LOG has log.message
237+
):
238238
# parsing the first slice
239239
current_slice_descriptor = self._parse_slice_description(message.log.message) # type: ignore[union-attr] # AirbyteMessage with MessageType.LOG has log.message
240240
elif message.type == MessageType.LOG:
@@ -274,14 +274,14 @@ def _get_message_groups(
274274
if message.trace.type == TraceType.ERROR: # type: ignore[union-attr] # AirbyteMessage with MessageType.TRACE has trace.type
275275
yield message.trace
276276
elif message.type == MessageType.RECORD:
277-
current_page_records.append(message.record.data) # type: ignore[union-attr] # AirbyteMessage with MessageType.RECORD has record.data
277+
current_page_records.append(message.record.data) # type: ignore[arg-type, union-attr] # AirbyteMessage with MessageType.RECORD has record.data
278278
records_count += 1
279279
schema_inferrer.accumulate(message.record)
280280
datetime_format_inferrer.accumulate(message.record)
281281
elif (
282282
message.type == MessageType.CONTROL
283-
and message.control.type == OrchestratorType.CONNECTOR_CONFIG
284-
): # type: ignore[union-attr] # AirbyteMessage with MessageType.CONTROL has control.type
283+
and message.control.type == OrchestratorType.CONNECTOR_CONFIG # type: ignore[union-attr] # None doesn't have 'type'
284+
):
285285
yield message.control
286286
elif message.type == MessageType.STATE:
287287
latest_state_message = message.state # type: ignore[assignment]
@@ -310,8 +310,8 @@ def _need_to_close_page(
310310
and message.type == MessageType.LOG
311311
and (
312312
MessageGrouper._is_page_http_request(json_message)
313-
or message.log.message.startswith("slice:")
314-
) # type: ignore[union-attr] # AirbyteMessage with MessageType.LOG has log.message
313+
or message.log.message.startswith("slice:") # type: ignore[union-attr] # AirbyteMessage with MessageType.LOG has log.message
314+
)
315315
)
316316

317317
@staticmethod
@@ -355,8 +355,8 @@ def _close_page(
355355
StreamReadPages(
356356
request=current_page_request,
357357
response=current_page_response,
358-
records=deepcopy(current_page_records),
359-
) # type: ignore
358+
records=deepcopy(current_page_records), # type: ignore [arg-type]
359+
)
360360
)
361361
current_page_records.clear()
362362

airbyte_cdk/destinations/destination.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from abc import ABC, abstractmethod
1010
from typing import Any, Iterable, List, Mapping
1111

12-
from orjson import orjson
12+
import orjson
1313

1414
from airbyte_cdk.connector import Connector
1515
from airbyte_cdk.exception_handler import init_uncaught_exception_handler

0 commit comments

Comments
 (0)