From 3dfcde5195eb7ac7012ec13dc2d1a4dd7d62d6a2 Mon Sep 17 00:00:00 2001 From: Aaron Steers Date: Sat, 9 Nov 2024 22:02:48 -0800 Subject: [PATCH] resolve ruff lint issues --- airbyte_cdk/models/airbyte_protocol.py | 4 ++- airbyte_cdk/models/well_known_types.py | 2 +- .../declarative/datetime/min_max_datetime.py | 2 +- .../file_based/file_types/csv_parser.py | 6 ++-- .../file_based/file_types/excel_parser.py | 2 +- pyproject.toml | 2 -- .../test_concurrent_read_processor.py | 29 ------------------- unit_tests/test/mock_http/test_mocker.py | 9 ------ 8 files changed, 9 insertions(+), 47 deletions(-) diff --git a/airbyte_cdk/models/airbyte_protocol.py b/airbyte_cdk/models/airbyte_protocol.py index b5d8683a8..6be79948e 100644 --- a/airbyte_cdk/models/airbyte_protocol.py +++ b/airbyte_cdk/models/airbyte_protocol.py @@ -6,9 +6,11 @@ from typing import Annotated, Any, Dict, List, Mapping, Optional, Union from airbyte_cdk.models.file_transfer_record_message import AirbyteFileTransferRecordMessage -from airbyte_protocol_dataclasses.models import * +from airbyte_protocol_dataclasses.models import * # noqa: F403 # Allow '*' from serpyco_rs.metadata import Alias +# ruff: noqa: F405 # ignore fuzzy import issues with 'import *' + @dataclass class AirbyteStateBlob: diff --git a/airbyte_cdk/models/well_known_types.py b/airbyte_cdk/models/well_known_types.py index a063ad7db..7b1ea492c 100644 --- a/airbyte_cdk/models/well_known_types.py +++ b/airbyte_cdk/models/well_known_types.py @@ -2,4 +2,4 @@ # Copyright (c) 2023 Airbyte, Inc., all rights reserved. # -from airbyte_protocol_dataclasses.models.well_known_types import * +from airbyte_protocol_dataclasses.models.well_known_types import * # noqa: F403 # Allow '*' diff --git a/airbyte_cdk/sources/declarative/datetime/min_max_datetime.py b/airbyte_cdk/sources/declarative/datetime/min_max_datetime.py index b53f50ff0..1edf92432 100644 --- a/airbyte_cdk/sources/declarative/datetime/min_max_datetime.py +++ b/airbyte_cdk/sources/declarative/datetime/min_max_datetime.py @@ -32,7 +32,7 @@ class MinMaxDatetime: parameters: InitVar[Mapping[str, Any]] # datetime_format is a unique case where we inherit it from the parent if it is not specified before using the default value # which is why we need dedicated getter/setter methods and private dataclass field - datetime_format: str = "" + datetime_format: str _datetime_format: str = field(init=False, repr=False, default="") min_datetime: Union[InterpolatedString, str] = "" max_datetime: Union[InterpolatedString, str] = "" 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 6927b2fdf..951be6fe2 100644 --- a/airbyte_cdk/sources/file_based/file_types/csv_parser.py +++ b/airbyte_cdk/sources/file_based/file_types/csv_parser.py @@ -362,7 +362,7 @@ def _cast_types( else: warnings.append(_format_warning(key, value, prop_type)) - elif python_type == bool: + elif python_type is bool: try: cast_value = _value_to_bool( value, config_format.true_values, config_format.false_values @@ -370,14 +370,14 @@ def _cast_types( except ValueError: warnings.append(_format_warning(key, value, prop_type)) - elif python_type == dict: + elif python_type is dict: try: # we don't re-use _value_to_object here because we type the column as object as long as there is only one object cast_value = orjson.loads(value) except orjson.JSONDecodeError: warnings.append(_format_warning(key, value, prop_type)) - elif python_type == list: + elif python_type is list: try: cast_value = _value_to_list(value) except (ValueError, json.JSONDecodeError): diff --git a/airbyte_cdk/sources/file_based/file_types/excel_parser.py b/airbyte_cdk/sources/file_based/file_types/excel_parser.py index 7a8b4e4b9..0c0da8b3f 100644 --- a/airbyte_cdk/sources/file_based/file_types/excel_parser.py +++ b/airbyte_cdk/sources/file_based/file_types/excel_parser.py @@ -151,7 +151,7 @@ def dtype_to_json_type(current_type: Optional[str], dtype: dtype_) -> str: if current_type == "string": # Previous column values were of the string type, no need to look further. return current_type - if dtype == object: + if dtype is object: return "string" if dtype in number_types and (not current_type or current_type == "number"): return "number" diff --git a/pyproject.toml b/pyproject.toml index 63c887800..c2a4c4d00 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -104,9 +104,7 @@ skip = ["__init__.py"] # TODO: Remove after this is fixed: https://github.com/a [tool.ruff] exclude = ["__init__.py"] # TODO: Remove after this is fixed: https://github.com/airbytehq/airbyte-python-cdk/issues/12 -# Setting python version to at least 3.10 avoids `from __future__ import annotations`. target-version = "py310" -# This is consistent with airbytehq/airbyte root pyproject.toml Black rule defined. line-length = 100 [tool.poe.tasks] diff --git a/unit_tests/sources/streams/concurrent/test_concurrent_read_processor.py b/unit_tests/sources/streams/concurrent/test_concurrent_read_processor.py index 68c7d7970..f6f6ecfba 100644 --- a/unit_tests/sources/streams/concurrent/test_concurrent_read_processor.py +++ b/unit_tests/sources/streams/concurrent/test_concurrent_read_processor.py @@ -735,35 +735,6 @@ def test_given_partition_completion_is_not_success_then_do_not_close_partition(s assert self._an_open_partition.close.call_count == 0 - def test_given_partition_completion_is_not_success_then_do_not_close_partition(self): - stream_instances_to_read_from = [self._stream, self._another_stream] - - handler = ConcurrentReadProcessor( - stream_instances_to_read_from, - self._partition_enqueuer, - self._thread_pool_manager, - self._logger, - self._slice_logger, - self._message_repository, - self._partition_reader, - ) - - handler.start_next_partition_generator() - handler.on_partition(self._an_open_partition) - list( - handler.on_partition_generation_completed( - PartitionGenerationCompletedSentinel(self._stream) - ) - ) - - list( - handler.on_partition_complete_sentinel( - PartitionCompleteSentinel(self._an_open_partition, not _IS_SUCCESSFUL) - ) - ) - - assert self._an_open_partition.close.call_count == 0 - def test_is_done_is_false_if_there_are_any_instances_to_read_from(self): stream_instances_to_read_from = [self._stream] diff --git a/unit_tests/test/mock_http/test_mocker.py b/unit_tests/test/mock_http/test_mocker.py index 9ca79ae5a..0aff08b9c 100644 --- a/unit_tests/test/mock_http/test_mocker.py +++ b/unit_tests/test/mock_http/test_mocker.py @@ -266,15 +266,6 @@ def decorated_function(http_mocker): with pytest.raises(ValueError): decorated_function() - def test_given_unknown_request_when_assert_number_of_calls_then_raise(self): - @HttpMocker() - def decorated_function(http_mocker): - http_mocker.get(HttpRequest(_A_URL), _A_RESPONSE) - http_mocker.assert_number_of_calls(HttpRequest(_ANOTHER_URL), 1) - - with pytest.raises(ValueError): - decorated_function() - def test_given_request_already_mocked_when_decorate_then_raise(self): with HttpMocker() as http_mocker: a_request = HttpRequest(_A_URL, _SOME_QUERY_PARAMS, _SOME_HEADERS)