From 39d66af4530e6a8c26137a15b3285d2265d7e263 Mon Sep 17 00:00:00 2001 From: Aaron Steers Date: Tue, 3 Dec 2024 13:58:06 -0800 Subject: [PATCH] remove unused type ignores --- airbyte_cdk/connector_builder/message_grouper.py | 8 ++++---- airbyte_cdk/entrypoint.py | 4 ++-- airbyte_cdk/logger.py | 2 +- airbyte_cdk/sources/abstract_source.py | 2 +- airbyte_cdk/sources/config.py | 2 +- airbyte_cdk/sources/connector_state_manager.py | 11 ++++++++--- airbyte_cdk/sources/declarative/auth/oauth.py | 2 +- .../declarative/concurrent_declarative_source.py | 2 +- .../declarative/incremental/datetime_based_cursor.py | 6 +++--- .../sources/declarative/interpolation/jinja.py | 2 +- .../sources/declarative/interpolation/macros.py | 2 +- .../declarative/parsers/model_to_component_factory.py | 11 +++++------ .../partition_routers/substream_partition_router.py | 4 ++-- .../error_handlers/default_error_handler.py | 2 +- .../requesters/error_handlers/http_response_filter.py | 6 +++--- .../datetime_based_request_options_provider.py | 2 +- airbyte_cdk/sources/declarative/spec/spec.py | 2 +- .../sources/file_based/file_types/csv_parser.py | 4 ++-- airbyte_cdk/sources/streams/concurrent/cursor.py | 2 +- .../datetime_stream_state_converter.py | 4 ++-- airbyte_cdk/sources/streams/core.py | 2 +- airbyte_cdk/sources/streams/http/http.py | 10 +++++----- airbyte_cdk/sources/streams/http/http_client.py | 4 ++-- airbyte_cdk/sources/utils/record_helper.py | 2 +- airbyte_cdk/sources/utils/schema_helpers.py | 2 +- airbyte_cdk/test/entrypoint_wrapper.py | 2 +- airbyte_cdk/test/mock_http/response_builder.py | 2 +- airbyte_cdk/utils/traced_exception.py | 4 ++-- 28 files changed, 56 insertions(+), 52 deletions(-) diff --git a/airbyte_cdk/connector_builder/message_grouper.py b/airbyte_cdk/connector_builder/message_grouper.py index 44ccdc5a7..ce43afab8 100644 --- a/airbyte_cdk/connector_builder/message_grouper.py +++ b/airbyte_cdk/connector_builder/message_grouper.py @@ -71,7 +71,7 @@ def _cursor_field_to_nested_and_composite_field( is_nested_key = isinstance(field[0], str) if is_nested_key: - return [field] # type: ignore # the type of field is expected to be List[str] here + return [field] raise ValueError(f"Unknown type for cursor field `{field}") @@ -234,7 +234,7 @@ def _get_message_groups( at_least_one_page_in_group = False elif message.type == MessageType.LOG and message.log.message.startswith( # type: ignore[union-attr] # None doesn't have 'message' SliceLogger.SLICE_LOG_PREFIX - ): # type: ignore[union-attr] # AirbyteMessage with MessageType.LOG has log.message + ): # parsing the first slice current_slice_descriptor = self._parse_slice_description(message.log.message) # type: ignore[union-attr] # AirbyteMessage with MessageType.LOG has log.message elif message.type == MessageType.LOG: @@ -281,7 +281,7 @@ def _get_message_groups( elif ( message.type == MessageType.CONTROL and message.control.type == OrchestratorType.CONNECTOR_CONFIG # type: ignore[union-attr] # None doesn't have 'type' - ): # type: ignore[union-attr] # AirbyteMessage with MessageType.CONTROL has control.type + ): yield message.control elif message.type == MessageType.STATE: latest_state_message = message.state # type: ignore[assignment] @@ -356,7 +356,7 @@ def _close_page( request=current_page_request, response=current_page_response, records=deepcopy(current_page_records), # type: ignore [arg-type] - ) # type: ignore + ) ) current_page_records.clear() diff --git a/airbyte_cdk/entrypoint.py b/airbyte_cdk/entrypoint.py index 19cb4dfe7..2864bbb0b 100644 --- a/airbyte_cdk/entrypoint.py +++ b/airbyte_cdk/entrypoint.py @@ -22,7 +22,7 @@ from airbyte_cdk.connector import TConfig from airbyte_cdk.exception_handler import init_uncaught_exception_handler from airbyte_cdk.logger import init_logger -from airbyte_cdk.models import ( # type: ignore [attr-defined] +from airbyte_cdk.models import ( AirbyteConnectionStatus, AirbyteMessage, AirbyteMessageSerializer, @@ -281,7 +281,7 @@ def set_up_secret_filter(config: TConfig, connection_specification: Mapping[str, @staticmethod def airbyte_message_to_string(airbyte_message: AirbyteMessage) -> str: - return orjson.dumps(AirbyteMessageSerializer.dump(airbyte_message)).decode() # type: ignore[no-any-return] # orjson.dumps(message).decode() always returns string + return orjson.dumps(AirbyteMessageSerializer.dump(airbyte_message)).decode() @classmethod def extract_state(cls, args: List[str]) -> Optional[Any]: diff --git a/airbyte_cdk/logger.py b/airbyte_cdk/logger.py index 48b25215d..78061b605 100644 --- a/airbyte_cdk/logger.py +++ b/airbyte_cdk/logger.py @@ -78,7 +78,7 @@ def format(self, record: logging.LogRecord) -> str: log_message = AirbyteMessage( type=Type.LOG, log=AirbyteLogMessage(level=airbyte_level, message=message) ) - return orjson.dumps(AirbyteMessageSerializer.dump(log_message)).decode() # type: ignore[no-any-return] # orjson.dumps(message).decode() always returns string + return orjson.dumps(AirbyteMessageSerializer.dump(log_message)).decode() @staticmethod def extract_extra_args_from_record(record: logging.LogRecord) -> Mapping[str, Any]: diff --git a/airbyte_cdk/sources/abstract_source.py b/airbyte_cdk/sources/abstract_source.py index 34ba816bc..ab9ee48b8 100644 --- a/airbyte_cdk/sources/abstract_source.py +++ b/airbyte_cdk/sources/abstract_source.py @@ -200,7 +200,7 @@ def read( if len(stream_name_to_exception) > 0: error_message = generate_failed_streams_error_message( {key: [value] for key, value in stream_name_to_exception.items()} - ) # type: ignore # for some reason, mypy can't figure out the types for key and value + ) logger.info(error_message) # We still raise at least one exception when a stream raises an exception because the platform currently relies # on a non-zero exit code to determine if a sync attempt has failed. We also raise the exception as a config_error diff --git a/airbyte_cdk/sources/config.py b/airbyte_cdk/sources/config.py index 8679ebbb7..ea91b17f3 100644 --- a/airbyte_cdk/sources/config.py +++ b/airbyte_cdk/sources/config.py @@ -24,4 +24,4 @@ def schema(cls, *args: Any, **kwargs: Any) -> Dict[str, Any]: rename_key(schema, old_key="anyOf", new_key="oneOf") # UI supports only oneOf expand_refs(schema) schema.pop("description", None) # description added from the docstring - return schema # type: ignore[no-any-return] + return schema diff --git a/airbyte_cdk/sources/connector_state_manager.py b/airbyte_cdk/sources/connector_state_manager.py index a53e7785d..914374a55 100644 --- a/airbyte_cdk/sources/connector_state_manager.py +++ b/airbyte_cdk/sources/connector_state_manager.py @@ -4,7 +4,7 @@ import copy from dataclasses import dataclass -from typing import Any, List, Mapping, MutableMapping, Optional, Tuple, Union +from typing import Any, List, Mapping, MutableMapping, Optional, Tuple, Union, cast from airbyte_cdk.models import ( AirbyteMessage, @@ -15,6 +15,7 @@ StreamDescriptor, ) from airbyte_cdk.models import Type as MessageType +from airbyte_cdk.models.airbyte_protocol import AirbyteGlobalState, AirbyteStateBlob @dataclass(frozen=True) @@ -118,8 +119,12 @@ def _extract_from_state_message( is_global = cls._is_global_state(state) if is_global: - global_state = state[0].global_ # type: ignore # We verified state is a list in _is_global_state - shared_state = copy.deepcopy(global_state.shared_state, {}) # type: ignore[union-attr] # global_state has shared_state + # We already validate that this is a global state message, not None: + global_state = cast(AirbyteGlobalState, state[0].global_) + # global_state has shared_state, also not None: + shared_state: AirbyteStateBlob = cast( + AirbyteStateBlob, copy.deepcopy(global_state.shared_state, {}) + ) streams = { HashableStreamDescriptor( name=per_stream_state.stream_descriptor.name, diff --git a/airbyte_cdk/sources/declarative/auth/oauth.py b/airbyte_cdk/sources/declarative/auth/oauth.py index 18bcc9fce..8ec671f3e 100644 --- a/airbyte_cdk/sources/declarative/auth/oauth.py +++ b/airbyte_cdk/sources/declarative/auth/oauth.py @@ -135,7 +135,7 @@ def get_grant_type(self) -> str: return self.grant_type.eval(self.config) # type: ignore # eval returns a string in this context def get_refresh_request_body(self) -> Mapping[str, Any]: - return self._refresh_request_body.eval(self.config) # type: ignore # eval should return a Mapping in this context + return self._refresh_request_body.eval(self.config) def get_token_expiry_date(self) -> pendulum.DateTime: return self._token_expiry_date # type: ignore # _token_expiry_date is a pendulum.DateTime. It is never None despite what mypy thinks diff --git a/airbyte_cdk/sources/declarative/concurrent_declarative_source.py b/airbyte_cdk/sources/declarative/concurrent_declarative_source.py index 40fd23edb..f41a1d287 100644 --- a/airbyte_cdk/sources/declarative/concurrent_declarative_source.py +++ b/airbyte_cdk/sources/declarative/concurrent_declarative_source.py @@ -128,7 +128,7 @@ def __init__( initial_number_of_partitions_to_generate=initial_number_of_partitions_to_generate, logger=self.logger, slice_logger=self._slice_logger, - message_repository=self.message_repository, # type: ignore # message_repository is always instantiated with a value by factory + message_repository=self.message_repository, ) def read( diff --git a/airbyte_cdk/sources/declarative/incremental/datetime_based_cursor.py b/airbyte_cdk/sources/declarative/incremental/datetime_based_cursor.py index 4c9df46d0..d6d329aec 100644 --- a/airbyte_cdk/sources/declarative/incremental/datetime_based_cursor.py +++ b/airbyte_cdk/sources/declarative/incremental/datetime_based_cursor.py @@ -134,7 +134,7 @@ def set_initial_state(self, stream_state: StreamState) -> None: """ self._cursor = ( stream_state.get(self.cursor_field.eval(self.config)) if stream_state else None # type: ignore [union-attr] - ) # type: ignore # cursor_field is converted to an InterpolatedString in __post_init__ + ) def observe(self, stream_slice: StreamSlice, record: Record) -> None: """ @@ -161,7 +161,7 @@ def observe(self, stream_slice: StreamSlice, record: Record) -> None: record, stream_slice.get(start_field), # type: ignore [arg-type] stream_slice.get(end_field), # type: ignore [arg-type] - ) # type: ignore # we know that stream_slices for these cursors will use a string representing an unparsed date + ) and is_highest_observed_cursor_value ): self._highest_observed_cursor_field_value = record_cursor_value @@ -372,7 +372,7 @@ def _get_request_options( if self.end_time_option and self.end_time_option.inject_into == option_type: options[self.end_time_option.field_name.eval(config=self.config)] = stream_slice.get( # type: ignore [union-attr] self._partition_field_end.eval(self.config) - ) # type: ignore # field_name is always casted to an interpolated string + ) return options def should_be_synced(self, record: Record) -> bool: diff --git a/airbyte_cdk/sources/declarative/interpolation/jinja.py b/airbyte_cdk/sources/declarative/interpolation/jinja.py index 71837b0d1..ec5e861cd 100644 --- a/airbyte_cdk/sources/declarative/interpolation/jinja.py +++ b/airbyte_cdk/sources/declarative/interpolation/jinja.py @@ -27,7 +27,7 @@ class StreamPartitionAccessEnvironment(SandboxedEnvironment): def is_safe_attribute(self, obj: Any, attr: str, value: Any) -> bool: if attr in ["_partition"]: return True - return super().is_safe_attribute(obj, attr, value) # type: ignore # for some reason, mypy says 'Returning Any from function declared to return "bool"' + return super().is_safe_attribute(obj, attr, value) class JinjaInterpolation(Interpolation): diff --git a/airbyte_cdk/sources/declarative/interpolation/macros.py b/airbyte_cdk/sources/declarative/interpolation/macros.py index ce448c127..e786f0116 100644 --- a/airbyte_cdk/sources/declarative/interpolation/macros.py +++ b/airbyte_cdk/sources/declarative/interpolation/macros.py @@ -116,7 +116,7 @@ def duration(datestring: str) -> Union[datetime.timedelta, isodate.Duration]: Usage: `"{{ now_utc() - duration('P1D') }}"` """ - return parse_duration(datestring) # type: ignore # mypy thinks this returns Any for some reason + return parse_duration(datestring) def format_datetime( diff --git a/airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py b/airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py index 49e047d37..331d4a464 100644 --- a/airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py +++ b/airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py @@ -397,7 +397,7 @@ def __init__( self._disable_retries = disable_retries self._disable_cache = disable_cache self._disable_resumable_full_refresh = disable_resumable_full_refresh - self._message_repository = message_repository or InMemoryMessageRepository( # type: ignore + self._message_repository = message_repository or InMemoryMessageRepository( self._evaluate_log_level(emit_connector_builder_messages) ) @@ -645,7 +645,7 @@ def create_legacy_to_per_partition_state_migration( declarative_stream.incremental_sync, # type: ignore # was already checked. Migration can be applied only to incremental streams. config, declarative_stream.parameters, # type: ignore # different type is expected here Mapping[str, Any], got Dict[str, Any] - ) # type: ignore # The retriever type was already checked + ) def create_session_token_authenticator( self, model: SessionTokenAuthenticatorModel, config: Config, name: str, **kwargs: Any @@ -675,7 +675,7 @@ def create_session_token_authenticator( return ModelToComponentFactory.create_bearer_authenticator( BearerAuthenticatorModel(type="BearerAuthenticator", api_token=""), # type: ignore # $parameters has a default value config, - token_provider=token_provider, # type: ignore # $parameters defaults to None + token_provider=token_provider, ) else: return ModelToComponentFactory.create_api_key_authenticator( @@ -822,7 +822,6 @@ def create_concurrent_cursor_from_datetime_based_cursor( input_datetime_formats=datetime_based_cursor_model.cursor_datetime_formats, is_sequential_state=True, cursor_granularity=cursor_granularity, - # type: ignore # Having issues w/ inspection for GapType and CursorValueType as shown in existing tests. Confirmed functionality is working in practice ) start_date_runtime_value: Union[InterpolatedString, str, MinMaxDatetime] @@ -896,7 +895,7 @@ def create_concurrent_cursor_from_datetime_based_cursor( stream_name=stream_name, stream_namespace=stream_namespace, stream_state=stream_state, - message_repository=self._message_repository, # type: ignore # message_repository is always instantiated with a value by factory + message_repository=self._message_repository, connector_state_manager=state_manager, connector_state_converter=connector_state_converter, cursor_field=cursor_field, @@ -1709,7 +1708,7 @@ def create_oauth_authenticator( refresh_token=model.refresh_token, scopes=model.scopes, token_expiry_date=model.token_expiry_date, - token_expiry_date_format=model.token_expiry_date_format, # type: ignore + token_expiry_date_format=model.token_expiry_date_format, token_expiry_is_time_of_expiration=bool(model.token_expiry_date_format), token_refresh_endpoint=model.token_refresh_endpoint, config=config, diff --git a/airbyte_cdk/sources/declarative/partition_routers/substream_partition_router.py b/airbyte_cdk/sources/declarative/partition_routers/substream_partition_router.py index adac145be..1c7bb6961 100644 --- a/airbyte_cdk/sources/declarative/partition_routers/substream_partition_router.py +++ b/airbyte_cdk/sources/declarative/partition_routers/substream_partition_router.py @@ -134,7 +134,7 @@ def _get_request_option( config=self.config ): value } - ) # type: ignore # field_name is always casted to an interpolated string + ) return params def stream_slices(self) -> Iterable[StreamSlice]: @@ -164,7 +164,7 @@ def stream_slices(self) -> Iterable[StreamSlice]: extra_fields = [ [field_path_part.eval(self.config) for field_path_part in field_path] # type: ignore [union-attr] for field_path in parent_stream_config.extra_fields - ] # type: ignore # extra_fields is always casted to an interpolated string + ] # read_stateless() assumes the parent is not concurrent. This is currently okay since the concurrent CDK does # not support either substreams or RFR, but something that needs to be considered once we do diff --git a/airbyte_cdk/sources/declarative/requesters/error_handlers/default_error_handler.py b/airbyte_cdk/sources/declarative/requesters/error_handlers/default_error_handler.py index 1340e8595..b70ceaaeb 100644 --- a/airbyte_cdk/sources/declarative/requesters/error_handlers/default_error_handler.py +++ b/airbyte_cdk/sources/declarative/requesters/error_handlers/default_error_handler.py @@ -141,7 +141,7 @@ def backoff_time( for backoff_strategy in self.backoff_strategies: backoff = backoff_strategy.backoff_time( response_or_exception=response_or_exception, attempt_count=attempt_count - ) # type: ignore # attempt_count maintained for compatibility with low code CDK + ) if backoff: return backoff return backoff diff --git a/airbyte_cdk/sources/declarative/requesters/error_handlers/http_response_filter.py b/airbyte_cdk/sources/declarative/requesters/error_handlers/http_response_filter.py index a64b31c27..a2fc80007 100644 --- a/airbyte_cdk/sources/declarative/requesters/error_handlers/http_response_filter.py +++ b/airbyte_cdk/sources/declarative/requesters/error_handlers/http_response_filter.py @@ -153,7 +153,7 @@ def _create_error_message(self, response: requests.Response) -> Optional[str]: """ return self.error_message.eval( # type: ignore [no-any-return, union-attr] self.config, response=self._safe_response_json(response), headers=response.headers - ) # type: ignore # error_message is always cast to an interpolated string + ) def _response_matches_predicate(self, response: requests.Response) -> bool: return ( @@ -161,13 +161,13 @@ def _response_matches_predicate(self, response: requests.Response) -> bool: self.predicate.condition # type: ignore [union-attr] and self.predicate.eval( # type: ignore [union-attr] None, # type: ignore [arg-type] - response=self._safe_response_json(response), # type: ignore [arg-type] + response=self._safe_response_json(response), headers=response.headers, ) ) if self.predicate else False - ) # type: ignore # predicate is always cast to an interpolated string + ) def _response_contains_error_message(self, response: requests.Response) -> bool: if not self.error_message_contains: diff --git a/airbyte_cdk/sources/declarative/requesters/request_options/datetime_based_request_options_provider.py b/airbyte_cdk/sources/declarative/requesters/request_options/datetime_based_request_options_provider.py index 9e9228c95..05e06db71 100644 --- a/airbyte_cdk/sources/declarative/requesters/request_options/datetime_based_request_options_provider.py +++ b/airbyte_cdk/sources/declarative/requesters/request_options/datetime_based_request_options_provider.py @@ -87,5 +87,5 @@ def _get_request_options( if self.end_time_option and self.end_time_option.inject_into == option_type: options[self.end_time_option.field_name.eval(config=self.config)] = stream_slice.get( # type: ignore [union-attr] self._partition_field_end.eval(self.config) - ) # type: ignore # field_name is always casted to an interpolated string + ) return options diff --git a/airbyte_cdk/sources/declarative/spec/spec.py b/airbyte_cdk/sources/declarative/spec/spec.py index 05fa079bf..914e99e93 100644 --- a/airbyte_cdk/sources/declarative/spec/spec.py +++ b/airbyte_cdk/sources/declarative/spec/spec.py @@ -9,7 +9,7 @@ AdvancedAuth, ConnectorSpecification, ConnectorSpecificationSerializer, -) # type: ignore [attr-defined] +) from airbyte_cdk.sources.declarative.models.declarative_component_schema import AuthFlow diff --git a/airbyte_cdk/sources/file_based/file_types/csv_parser.py b/airbyte_cdk/sources/file_based/file_types/csv_parser.py index a367d7ead..e3010690e 100644 --- a/airbyte_cdk/sources/file_based/file_types/csv_parser.py +++ b/airbyte_cdk/sources/file_based/file_types/csv_parser.py @@ -117,7 +117,7 @@ def _get_headers(self, fp: IOBase, config_format: CsvFormat, dialect_name: str) """ # Note that this method assumes the dialect has already been registered if we're parsing the headers if isinstance(config_format.header_definition, CsvHeaderUserProvided): - return config_format.header_definition.column_names # type: ignore # should be CsvHeaderUserProvided given the type + return config_format.header_definition.column_names if isinstance(config_format.header_definition, CsvHeaderAutogenerated): self._skip_rows( @@ -229,7 +229,7 @@ def parse_records( if discovered_schema: property_types = { col: prop["type"] for col, prop in discovered_schema["properties"].items() - } # type: ignore # discovered_schema["properties"] is known to be a mapping + } deduped_property_types = CsvParser._pre_propcess_property_types(property_types) else: deduped_property_types = {} diff --git a/airbyte_cdk/sources/streams/concurrent/cursor.py b/airbyte_cdk/sources/streams/concurrent/cursor.py index 4f103b224..cbce82a94 100644 --- a/airbyte_cdk/sources/streams/concurrent/cursor.py +++ b/airbyte_cdk/sources/streams/concurrent/cursor.py @@ -473,7 +473,7 @@ def should_be_synced(self, record: Record) -> bool: :return: True if the record's cursor value falls within the sync boundaries """ try: - record_cursor_value: CursorValueType = self._extract_cursor_value(record) # type: ignore # cursor_field is converted to an InterpolatedString in __post_init__ + record_cursor_value: CursorValueType = self._extract_cursor_value(record) except ValueError: self._log_for_record_without_cursor_value() return True diff --git a/airbyte_cdk/sources/streams/concurrent/state_converters/datetime_stream_state_converter.py b/airbyte_cdk/sources/streams/concurrent/state_converters/datetime_stream_state_converter.py index 714789af3..3f53a9234 100644 --- a/airbyte_cdk/sources/streams/concurrent/state_converters/datetime_stream_state_converter.py +++ b/airbyte_cdk/sources/streams/concurrent/state_converters/datetime_stream_state_converter.py @@ -141,7 +141,7 @@ def parse_timestamp(self, timestamp: int) -> datetime: raise ValueError( f"DateTime object was expected but got {type(dt_object)} from pendulum.parse({timestamp})" ) - return dt_object # type: ignore # we are manually type checking because pendulum.parse may return different types + return dt_object class IsoMillisConcurrentStreamStateConverter(DateTimeStreamStateConverter): @@ -178,7 +178,7 @@ def parse_timestamp(self, timestamp: str) -> datetime: raise ValueError( f"DateTime object was expected but got {type(dt_object)} from pendulum.parse({timestamp})" ) - return dt_object # type: ignore # we are manually type checking because pendulum.parse may return different types + return dt_object class CustomFormatConcurrentStreamStateConverter(IsoMillisConcurrentStreamStateConverter): diff --git a/airbyte_cdk/sources/streams/core.py b/airbyte_cdk/sources/streams/core.py index 6973d94ff..d908be675 100644 --- a/airbyte_cdk/sources/streams/core.py +++ b/airbyte_cdk/sources/streams/core.py @@ -317,7 +317,7 @@ def as_airbyte_stream(self) -> AirbyteStream: # If we can offer incremental we always should. RFR is always less reliable than incremental which uses a real cursor value if self.supports_incremental: stream.source_defined_cursor = self.source_defined_cursor - stream.supported_sync_modes.append(SyncMode.incremental) # type: ignore + stream.supported_sync_modes.append(SyncMode.incremental) stream.default_cursor_field = self._wrapped_cursor_field() keys = Stream._wrapped_primary_key(self.primary_key) diff --git a/airbyte_cdk/sources/streams/http/http.py b/airbyte_cdk/sources/streams/http/http.py index e6cb84277..40eab27a3 100644 --- a/airbyte_cdk/sources/streams/http/http.py +++ b/airbyte_cdk/sources/streams/http/http.py @@ -639,15 +639,15 @@ def interpret_response( return ErrorResolution( response_action=ResponseAction.RATE_LIMITED, failure_type=FailureType.transient_error, - error_message=f"Response status code: {response_or_exception.status_code}. Retrying...", # type: ignore[union-attr] + error_message=f"Response status code: {response_or_exception.status_code}. Retrying...", ) return ErrorResolution( response_action=ResponseAction.RETRY, failure_type=FailureType.transient_error, - error_message=f"Response status code: {response_or_exception.status_code}. Retrying...", # type: ignore[union-attr] + error_message=f"Response status code: {response_or_exception.status_code}. Retrying...", ) else: - if response_or_exception.ok: # type: ignore # noqa + if response_or_exception.ok: return ErrorResolution( response_action=ResponseAction.SUCCESS, failure_type=None, @@ -657,13 +657,13 @@ def interpret_response( return ErrorResolution( response_action=ResponseAction.FAIL, failure_type=FailureType.transient_error, - error_message=f"Response status code: {response_or_exception.status_code}. Unexpected error. Failed.", # type: ignore[union-attr] + error_message=f"Response status code: {response_or_exception.status_code}. Unexpected error. Failed.", ) else: return ErrorResolution( response_action=ResponseAction.IGNORE, failure_type=FailureType.transient_error, - error_message=f"Response status code: {response_or_exception.status_code}. Ignoring...", # type: ignore[union-attr] + error_message=f"Response status code: {response_or_exception.status_code}. Ignoring...", ) else: self._logger.error(f"Received unexpected response type: {type(response_or_exception)}") diff --git a/airbyte_cdk/sources/streams/http/http_client.py b/airbyte_cdk/sources/streams/http/http_client.py index 91e2a63d9..4f99bbeba 100644 --- a/airbyte_cdk/sources/streams/http/http_client.py +++ b/airbyte_cdk/sources/streams/http/http_client.py @@ -144,7 +144,7 @@ def _request_session(self) -> requests.Session: sqlite_path = "file::memory:?cache=shared" return CachedLimiterSession( sqlite_path, backend="sqlite", api_budget=self._api_budget, match_headers=True - ) # type: ignore # there are no typeshed stubs for requests_cache + ) else: return LimiterSession(api_budget=self._api_budget) @@ -324,7 +324,7 @@ def _send( formatter = log_formatter self._message_repository.log_message( Level.DEBUG, - lambda: formatter(response), # type: ignore # log_formatter is always cast to a callable + lambda: formatter(response), ) self._handle_error_resolution( diff --git a/airbyte_cdk/sources/utils/record_helper.py b/airbyte_cdk/sources/utils/record_helper.py index e45601c22..3d2cbcecf 100644 --- a/airbyte_cdk/sources/utils/record_helper.py +++ b/airbyte_cdk/sources/utils/record_helper.py @@ -35,7 +35,7 @@ def stream_data_to_airbyte_message( # need it to normalize values against json schema. By default no action # taken unless configured. See # docs/connector-development/cdk-python/schemas.md for details. - transformer.transform(data, schema) # type: ignore + transformer.transform(data, schema) if is_file_transfer_message: message = AirbyteFileTransferRecordMessage( stream=stream_name, file=data, emitted_at=now_millis, data={} diff --git a/airbyte_cdk/sources/utils/schema_helpers.py b/airbyte_cdk/sources/utils/schema_helpers.py index b8d2507c6..f15578238 100644 --- a/airbyte_cdk/sources/utils/schema_helpers.py +++ b/airbyte_cdk/sources/utils/schema_helpers.py @@ -194,7 +194,7 @@ class InternalConfig(BaseModel): def dict(self, *args: Any, **kwargs: Any) -> dict[str, Any]: kwargs["by_alias"] = True kwargs["exclude_unset"] = True - return super().dict(*args, **kwargs) # type: ignore[no-any-return] + return super().dict(*args, **kwargs) def is_limit_reached(self, records_counter: int) -> bool: """ diff --git a/airbyte_cdk/test/entrypoint_wrapper.py b/airbyte_cdk/test/entrypoint_wrapper.py index 60514bf73..f8e85bfb0 100644 --- a/airbyte_cdk/test/entrypoint_wrapper.py +++ b/airbyte_cdk/test/entrypoint_wrapper.py @@ -63,7 +63,7 @@ def __init__(self, messages: List[str], uncaught_exception: Optional[BaseExcepti @staticmethod def _parse_message(message: str) -> AirbyteMessage: try: - return AirbyteMessageSerializer.load(orjson.loads(message)) # type: ignore[no-any-return] # Serializer.load() always returns AirbyteMessage + return AirbyteMessageSerializer.load(orjson.loads(message)) except (orjson.JSONDecodeError, SchemaValidationError): # The platform assumes that logs that are not of AirbyteMessage format are log messages return AirbyteMessage( diff --git a/airbyte_cdk/test/mock_http/response_builder.py b/airbyte_cdk/test/mock_http/response_builder.py index b517343e6..7f9583827 100644 --- a/airbyte_cdk/test/mock_http/response_builder.py +++ b/airbyte_cdk/test/mock_http/response_builder.py @@ -183,7 +183,7 @@ def build(self) -> HttpResponse: def _get_unit_test_folder(execution_folder: str) -> FilePath: # FIXME: This function should be removed after the next CDK release to avoid breaking amazon-seller-partner test code. - return get_unit_test_folder(execution_folder) # type: ignore # get_unit_test_folder is known to return a FilePath + return get_unit_test_folder(execution_folder) def find_template(resource: str, execution_folder: str) -> Dict[str, Any]: diff --git a/airbyte_cdk/utils/traced_exception.py b/airbyte_cdk/utils/traced_exception.py index 54c1e52e0..59dbab2a5 100644 --- a/airbyte_cdk/utils/traced_exception.py +++ b/airbyte_cdk/utils/traced_exception.py @@ -106,7 +106,7 @@ def from_exception( stream_descriptor: Optional[StreamDescriptor] = None, *args: Any, **kwargs: Any, - ) -> "AirbyteTracedException": # type: ignore # ignoring because of args and kwargs + ) -> "AirbyteTracedException": """ Helper to create an AirbyteTracedException from an existing exception :param exc: the exception that caused the error @@ -133,7 +133,7 @@ def as_sanitized_airbyte_message( if error_message.trace.error.message: # type: ignore[union-attr] # AirbyteMessage with MessageType.TRACE has AirbyteTraceMessage error_message.trace.error.message = filter_secrets( # type: ignore[union-attr] error_message.trace.error.message, # type: ignore[union-attr] - ) # type: ignore[union-attr] # AirbyteMessage with MessageType.TRACE has AirbyteTraceMessage + ) if error_message.trace.error.internal_message: # type: ignore[union-attr] # AirbyteMessage with MessageType.TRACE has AirbyteTraceMessage error_message.trace.error.internal_message = filter_secrets( # type: ignore[union-attr] # AirbyteMessage with MessageType.TRACE has AirbyteTraceMessage error_message.trace.error.internal_message # type: ignore[union-attr] # AirbyteMessage with MessageType.TRACE has AirbyteTraceMessage