Skip to content

Commit 8202ce5

Browse files
committed
chore: misc mypy typing fixes
1 parent f54eb7c commit 8202ce5

File tree

24 files changed

+214
-121
lines changed

24 files changed

+214
-121
lines changed

.github/dependabot.yml

+4-4
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/publish_sdm_connector.yml

+5-8
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ on:
77
workflow_dispatch:
88
inputs:
99
version:
10-
description:
11-
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.
10+
description: The version to publish, ie 1.0.0 or 1.0.0-dev1.
11+
If omitted, and if run from a release branch, the version will be
12+
inferred from the git tag.
13+
If omitted, and if run from a non-release branch, then only a SHA-based
14+
Docker tag will be created.
1615
required: false
1716
dry_run:
1817
description: If true, the workflow will not push to DockerHub.
@@ -24,7 +23,6 @@ jobs:
2423
build:
2524
runs-on: ubuntu-latest
2625
steps:
27-
2826
- name: Detect Release Tag Version
2927
if: startsWith(github.ref, 'refs/tags/v')
3028
run: |
@@ -167,7 +165,6 @@ jobs:
167165
tags: |
168166
airbyte/source-declarative-manifest:${{ env.VERSION }}
169167
170-
171168
- name: Build and push ('latest' tag)
172169
# Only run if version is set and IS_PRERELEASE is false
173170
if: env.VERSION != '' && env.IS_PRERELEASE == 'false' && github.event.inputs.dry_run == 'false'

.github/workflows/pytest_matrix.yml

+4-4
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:

airbyte_cdk/cli/source_declarative_manifest/_run.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,14 @@ def create_declarative_source(args: list[str]) -> ConcurrentDeclarativeSource:
160160
connector builder.
161161
"""
162162
try:
163+
config: Mapping[str, Any] | None
164+
catalog: ConfiguredAirbyteCatalog | None
165+
state: list[AirbyteStateMessage]
163166
config, catalog, state = _parse_inputs_into_config_catalog_state(args)
164-
if "__injected_declarative_manifest" not in config:
167+
if config is None or "__injected_declarative_manifest" not in config:
165168
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())}"
169+
"Invalid config: `__injected_declarative_manifest` should be provided at the root "
170+
f"of the config but config only has keys: {list(config.keys() if config else [])}"
167171
)
168172
return ConcurrentDeclarativeSource(
169173
config=config,

airbyte_cdk/destinations/vector_db_based/writer.py

+3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ def write(
8585
record_chunks, record_id_to_delete = self.processor.process(message.record)
8686
self.chunks[(message.record.namespace, message.record.stream)].extend(record_chunks)
8787
if record_id_to_delete is not None:
88+
if message.record is None:
89+
raise ValueError("Record messages cannot have null `record` property.")
90+
8891
self.ids_to_delete[(message.record.namespace, message.record.stream)].append(
8992
record_id_to_delete
9093
)

airbyte_cdk/sources/connector_state_manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def _extract_from_state_message(
131131
else:
132132
streams = {
133133
HashableStreamDescriptor(
134-
name=per_stream_state.stream.stream_descriptor.name,
134+
name=per_stream_state.stream.stream_descriptor.name, # type: ignore[union-attr] # stream has stream_descriptor
135135
namespace=per_stream_state.stream.stream_descriptor.namespace, # type: ignore[union-attr] # stream has stream_descriptor
136136
): per_stream_state.stream.stream_state # type: ignore[union-attr] # stream has stream_state
137137
for per_stream_state in state

airbyte_cdk/sources/declarative/auth/selective_authenticator.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ def __new__( # type: ignore[misc]
2828
**kwargs: Any,
2929
) -> DeclarativeAuthenticator:
3030
try:
31-
selected_key = str(dpath.get(config, authenticator_selection_path))
31+
selected_key = str(
32+
dpath.get(
33+
config, # type: ignore [arg-type] # Dpath wants mutable mapping but doesn't need it.
34+
authenticator_selection_path,
35+
)
36+
)
3237
except KeyError as err:
3338
raise ValueError(
3439
"The path from `authenticator_selection_path` is not found in the config."

airbyte_cdk/sources/declarative/declarative_component_schema.yaml

+16-17
Original file line numberDiff line numberDiff line change
@@ -2044,17 +2044,18 @@ definitions:
20442044
The DeclarativeOAuth Specific URL templated string to obtain the `access_token`, `refresh_token` etc.
20452045
The placeholders are replaced during the processing to provide neccessary values.
20462046
examples:
2047-
- access_token_url: https://auth.host.com/oauth2/token?{client_id_key}={{client_id_key}}&{client_secret_key}={{client_secret_key}}&{auth_code_key}={{auth_code_key}}&{redirect_uri_key}={urlEncoder:{{redirect_uri_key}}}
2047+
- access_token_url: https://auth.host.com/oauth2/token?{client_id_key}={{client_id_key}}&{client_secret_key}={{client_secret_key}}&{auth_code_key}={{auth_code_key}}&{redirect_uri_key}={urlEncoder:{{redirect_uri_key}}}
20482048
access_token_headers:
20492049
title: (Optional) DeclarativeOAuth Access Token Headers
20502050
type: object
20512051
additionalProperties: true
20522052
description: |-
20532053
The DeclarativeOAuth Specific optional headers to inject while exchanging the `auth_code` to `access_token` during `completeOAuthFlow` step.
20542054
examples:
2055-
- access_token_headers: {
2056-
"Authorization": "Basic {base64Encoder:{client_id}:{client_secret}}"
2057-
}
2055+
- access_token_headers:
2056+
{
2057+
"Authorization": "Basic {base64Encoder:{client_id}:{client_secret}}",
2058+
}
20582059
access_token_params:
20592060
title: (Optional) DeclarativeOAuth Access Token Query Params (Json Encoded)
20602061
type: object
@@ -2063,18 +2064,19 @@ definitions:
20632064
The DeclarativeOAuth Specific optional query parameters to inject while exchanging the `auth_code` to `access_token` during `completeOAuthFlow` step.
20642065
When this property is provided, the query params will be encoded as `Json` and included in the outgoing API request.
20652066
examples:
2066-
- access_token_params: {
2067-
"{auth_code_key}": "{{auth_code_key}}",
2068-
"{client_id_key}": "{{client_id_key}}",
2069-
"{client_secret_key}": "{{client_secret_key}}"
2070-
}
2067+
- access_token_params:
2068+
{
2069+
"{auth_code_key}": "{{auth_code_key}}",
2070+
"{client_id_key}": "{{client_id_key}}",
2071+
"{client_secret_key}": "{{client_secret_key}}",
2072+
}
20712073
extract_output:
20722074
title: DeclarativeOAuth Extract Output
20732075
type: array
20742076
items:
20752077
type: string
20762078
description: |-
2077-
The DeclarativeOAuth Specific list of strings to indicate which keys should be extracted and returned back to the input config.
2079+
The DeclarativeOAuth Specific list of strings to indicate which keys should be extracted and returned back to the input config.
20782080
examples:
20792081
- extract_output: ["access_token", "refresh_token", "other_field"]
20802082
state:
@@ -2086,17 +2088,14 @@ definitions:
20862088
- max
20872089
description: |-
20882090
The DeclarativeOAuth Specific object to provide the criteria of how the `state` query param should be constructed,
2089-
including length and complexity.
2091+
including length and complexity.
20902092
properties:
20912093
min:
20922094
type: integer
20932095
max:
20942096
type: integer
20952097
examples:
2096-
- state: {
2097-
"min": 7,
2098-
"max": 128,
2099-
}
2098+
- state: { "min": 7, "max": 128 }
21002099
client_id_key:
21012100
title: (Optional) DeclarativeOAuth Client ID Key Override
21022101
type: string
@@ -2122,14 +2121,14 @@ definitions:
21222121
title: (Optional) DeclarativeOAuth State Key Override
21232122
type: string
21242123
description: |-
2125-
The DeclarativeOAuth Specific optional override to provide the custom `state` key name, if required by data-provider.
2124+
The DeclarativeOAuth Specific optional override to provide the custom `state` key name, if required by data-provider.
21262125
examples:
21272126
- state_key: "my_custom_state_key_key_name"
21282127
auth_code_key:
21292128
title: (Optional) DeclarativeOAuth Auth Code Key Override
21302129
type: string
21312130
description: |-
2132-
The DeclarativeOAuth Specific optional override to provide the custom `code` key name to something like `auth_code` or `custom_auth_code`, if required by data-provider.
2131+
The DeclarativeOAuth Specific optional override to provide the custom `code` key name to something like `auth_code` or `custom_auth_code`, if required by data-provider.
21332132
examples:
21342133
- auth_code_key: "my_custom_auth_code_key_name"
21352134
redirect_uri_key:

airbyte_cdk/sources/declarative/decoders/noop_decoder.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ class NoopDecoder(Decoder):
1414
def is_stream_response(self) -> bool:
1515
return False
1616

17-
def decode(self, response: requests.Response) -> Generator[Mapping[str, Any], None, None]:
17+
def decode( # type: ignore[override]
18+
self,
19+
response: requests.Response,
20+
) -> Generator[Mapping[str, Any], None, None]:
1821
yield from [{}]

airbyte_cdk/sources/file_based/availability_strategy/abstract_file_based_availability_strategy.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222

2323
class AbstractFileBasedAvailabilityStrategy(AvailabilityStrategy):
2424
@abstractmethod
25-
def check_availability(
26-
self, stream: Stream, logger: logging.Logger, _: Optional[Source]
25+
def check_availability( # type: ignore[override]
26+
self,
27+
stream: Stream,
28+
logger: logging.Logger,
29+
_: Optional[Source],
2730
) -> Tuple[bool, Optional[str]]:
2831
"""
2932
Perform a connection check for the stream.
@@ -34,7 +37,10 @@ def check_availability(
3437

3538
@abstractmethod
3639
def check_availability_and_parsability(
37-
self, stream: "AbstractFileBasedStream", logger: logging.Logger, _: Optional[Source]
40+
self,
41+
stream: AbstractFileBasedStream,
42+
logger: logging.Logger,
43+
_: Optional[Source],
3844
) -> Tuple[bool, Optional[str]]:
3945
"""
4046
Performs a connection check for the stream, as well as additional checks that
@@ -46,7 +52,7 @@ def check_availability_and_parsability(
4652

4753

4854
class AbstractFileBasedAvailabilityStrategyWrapper(AbstractAvailabilityStrategy):
49-
def __init__(self, stream: "AbstractFileBasedStream"):
55+
def __init__(self, stream: AbstractFileBasedStream) -> None:
5056
self.stream = stream
5157

5258
def check_availability(self, logger: logging.Logger) -> StreamAvailability:

airbyte_cdk/sources/file_based/availability_strategy/default_file_based_availability_strategy.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ class DefaultFileBasedAvailabilityStrategy(AbstractFileBasedAvailabilityStrategy
2828
def __init__(self, stream_reader: AbstractFileBasedStreamReader):
2929
self.stream_reader = stream_reader
3030

31-
def check_availability(
32-
self, stream: "AbstractFileBasedStream", logger: logging.Logger, _: Optional[Source]
33-
) -> Tuple[bool, Optional[str]]: # type: ignore[override]
31+
def check_availability( # type: ignore[override]
32+
self,
33+
stream: AbstractFileBasedStream,
34+
logger: logging.Logger,
35+
_: Optional[Source],
36+
) -> Tuple[bool, Optional[str]]:
3437
"""
3538
Perform a connection check for the stream (verify that we can list files from the stream).
3639
@@ -44,7 +47,10 @@ def check_availability(
4447
return True, None
4548

4649
def check_availability_and_parsability(
47-
self, stream: "AbstractFileBasedStream", logger: logging.Logger, _: Optional[Source]
50+
self,
51+
stream: AbstractFileBasedStream,
52+
logger: logging.Logger,
53+
_: Optional[Source],
4854
) -> Tuple[bool, Optional[str]]:
4955
"""
5056
Perform a connection check for the stream.
@@ -82,7 +88,7 @@ def check_availability_and_parsability(
8288

8389
return True, None
8490

85-
def _check_list_files(self, stream: "AbstractFileBasedStream") -> RemoteFile:
91+
def _check_list_files(self, stream: AbstractFileBasedStream) -> RemoteFile:
8692
"""
8793
Check that we can list files from the stream.
8894
@@ -102,7 +108,10 @@ def _check_list_files(self, stream: "AbstractFileBasedStream") -> RemoteFile:
102108
return file
103109

104110
def _check_parse_record(
105-
self, stream: "AbstractFileBasedStream", file: RemoteFile, logger: logging.Logger
111+
self,
112+
stream: AbstractFileBasedStream,
113+
file: RemoteFile,
114+
logger: logging.Logger,
106115
) -> None:
107116
parser = stream.get_parser()
108117

airbyte_cdk/sources/file_based/file_types/avro_parser.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44

55
import logging
6-
from typing import Any, Dict, Iterable, Mapping, Optional, Tuple
6+
from typing import Any, Dict, Iterable, Mapping, Optional, Tuple, cast
77

88
import fastavro
99

@@ -183,7 +183,7 @@ def parse_records(
183183
avro_reader = fastavro.reader(fp)
184184
schema = avro_reader.writer_schema
185185
schema_field_name_to_type = {
186-
field["name"]: field["type"] for field in schema["fields"]
186+
field["name"]: cast(dict, field["type"]) for field in schema["fields"]
187187
}
188188
for record in avro_reader:
189189
line_no += 1

airbyte_cdk/sources/streams/concurrent/cursor.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ def observe(self, record: Record) -> None:
218218
)
219219
cursor_value = self._extract_cursor_value(record)
220220

221-
if most_recent_cursor_value is None or most_recent_cursor_value < cursor_value:
221+
if record.associated_slice is not None and (
222+
most_recent_cursor_value is None or most_recent_cursor_value < cursor_value
223+
):
222224
self._most_recent_cursor_value_per_partition[record.associated_slice] = cursor_value
223225

224226
def _extract_cursor_value(self, record: Record) -> Any:

airbyte_cdk/sources/streams/core.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,6 @@ class StreamClassification:
115115
has_multiple_slices: bool
116116

117117

118-
# Moved to class declaration since get_updated_state is called on every record for incremental syncs, and thus the @deprecated decorator as well.
119-
@deprecated(
120-
"Deprecated as of CDK version 0.1.49. ",
121-
"Deprecated method get_updated_state, You should use explicit state property instead, see IncrementalMixin docs.",
122-
)
123118
class Stream(ABC):
124119
"""
125120
Base abstract class for an Airbyte Stream. Makes no assumption of the Stream's underlying transport protocol.
@@ -435,6 +430,10 @@ def state_checkpoint_interval(self) -> Optional[int]:
435430
"""
436431
return None
437432

433+
@deprecated(
434+
"Deprecated method `get_updated_state` as of CDK version 0.1.49. "
435+
"Please use explicit state property instead, see `IncrementalMixin` docs.",
436+
)
438437
def get_updated_state(
439438
self, current_stream_state: MutableMapping[str, Any], latest_record: Mapping[str, Any]
440439
) -> MutableMapping[str, Any]:

airbyte_cdk/sources/streams/http/requests_native_auth/abstract_token.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
from abc import abstractmethod
66
from typing import Any, Mapping
77

8+
import requests
89
from requests.auth import AuthBase
910

1011

1112
class AbstractHeaderAuthenticator(AuthBase):
1213
"""Abstract class for an header-based authenticators that add a header to outgoing HTTP requests."""
1314

14-
def __call__(self, request):
15+
def __call__(self, request: requests.PreparedRequest) -> Any:
1516
"""Attach the HTTP headers required to authenticate on the HTTP request"""
1617
request.headers.update(self.get_auth_header())
1718
return request

0 commit comments

Comments
 (0)