Skip to content

Commit

Permalink
Fix E721 errors in the CDK (#36490)
Browse files Browse the repository at this point in the history
  • Loading branch information
erohmensing authored Mar 26, 2024
1 parent 9dee837 commit 0c36768
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 192 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


from dataclasses import InitVar, dataclass
from typing import Any, Mapping, Optional
from typing import Any, Dict, Mapping, Optional

from airbyte_cdk.sources.declarative.interpolation.jinja import JinjaInterpolation
from airbyte_cdk.sources.declarative.types import Config
Expand All @@ -22,17 +22,17 @@ class InterpolatedMapping:
mapping: Mapping[str, str]
parameters: InitVar[Mapping[str, Any]]

def __post_init__(self, parameters: Optional[Mapping[str, Any]]):
def __post_init__(self, parameters: Optional[Mapping[str, Any]]) -> None:
self._interpolation = JinjaInterpolation()
self._parameters = parameters

def eval(self, config: Config, **additional_parameters):
def eval(self, config: Config, **additional_parameters: Any) -> Dict[str, Any]:
"""
Wrapper around a Mapping[str, str] that allows for both keys and values to be interpolated.
:param config: The user-provided configuration as specified by the source's spec
:param additional_parameters: Optional parameters used for interpolation
:return: The interpolated string
:return: The interpolated mapping
"""
valid_key_types = additional_parameters.pop("valid_key_types", (str,))
valid_value_types = additional_parameters.pop("valid_value_types", None)
Expand All @@ -43,10 +43,10 @@ def eval(self, config: Config, **additional_parameters):
for name, value in self.mapping.items()
}

def _eval(self, value, config, **kwargs):
def _eval(self, value: str, config: Config, **kwargs: Any) -> Any:
# The values in self._mapping can be of Any type
# We only want to interpolate them if they are strings
if type(value) == str:
if isinstance(value, str):
return self._interpolation.eval(value, config, parameters=self._parameters, **kwargs)
else:
return value
Original file line number Diff line number Diff line change
Expand Up @@ -1725,10 +1725,10 @@ def test_merge_incremental_and_partition_router(incremental, partition_router, e

if incremental and partition_router:
assert isinstance(stream.retriever.stream_slicer, PerPartitionCursor)
if type(partition_router) == list and len(partition_router) > 1:
assert type(stream.retriever.stream_slicer._partition_router) == CartesianProductStreamSlicer
if isinstance(partition_router, list) and len(partition_router) > 1:
assert isinstance(stream.retriever.stream_slicer._partition_router, CartesianProductStreamSlicer)
assert len(stream.retriever.stream_slicer._partition_router.stream_slicers) == len(partition_router)
elif partition_router and type(partition_router) == list and len(partition_router) > 1:
elif partition_router and isinstance(partition_router, list) and len(partition_router) > 1:
assert isinstance(stream.retriever.stream_slicer, PerPartitionCursor)
assert len(stream.retriever.stream_slicer.stream_slicerS) == len(partition_router)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_started_as_message():
stream_status = AirbyteStreamStatus.STARTED
airbyte_message = stream_status_as_airbyte_message(stream, stream_status)

assert type(airbyte_message) == AirbyteMessage
assert isinstance(airbyte_message, AirbyteMessage)
assert airbyte_message.type == MessageType.TRACE
assert airbyte_message.trace.type == TraceType.STREAM_STATUS
assert airbyte_message.trace.emitted_at > 0
Expand All @@ -26,7 +26,7 @@ def test_running_as_message():
stream_status = AirbyteStreamStatus.RUNNING
airbyte_message = stream_status_as_airbyte_message(stream, stream_status)

assert type(airbyte_message) == AirbyteMessage
assert isinstance(airbyte_message, AirbyteMessage)
assert airbyte_message.type == MessageType.TRACE
assert airbyte_message.trace.type == TraceType.STREAM_STATUS
assert airbyte_message.trace.emitted_at > 0
Expand All @@ -39,7 +39,7 @@ def test_complete_as_message():
stream_status = AirbyteStreamStatus.COMPLETE
airbyte_message = stream_status_as_airbyte_message(stream, stream_status)

assert type(airbyte_message) == AirbyteMessage
assert isinstance(airbyte_message, AirbyteMessage)
assert airbyte_message.type == MessageType.TRACE
assert airbyte_message.trace.type == TraceType.STREAM_STATUS
assert airbyte_message.trace.emitted_at > 0
Expand All @@ -52,7 +52,7 @@ def test_incomplete_failed_as_message():
stream_status = AirbyteStreamStatus.INCOMPLETE
airbyte_message = stream_status_as_airbyte_message(stream, stream_status)

assert type(airbyte_message) == AirbyteMessage
assert isinstance(airbyte_message, AirbyteMessage)
assert airbyte_message.type == MessageType.TRACE
assert airbyte_message.trace.type == TraceType.STREAM_STATUS
assert airbyte_message.trace.emitted_at > 0
Expand Down
6 changes: 3 additions & 3 deletions airbyte-cdk/python/unit_tests/utils/test_traced_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_exception_as_airbyte_message():
traced_exc = AirbyteTracedException("an internal message")
airbyte_message = traced_exc.as_airbyte_message()

assert type(airbyte_message) == AirbyteMessage
assert isinstance(airbyte_message, AirbyteMessage)
assert airbyte_message.type == MessageType.TRACE
assert airbyte_message.trace.type == TraceType.ERROR
assert airbyte_message.trace.emitted_at > 0
Expand All @@ -51,7 +51,7 @@ def test_existing_exception_as_airbyte_message(raised_exception):
traced_exc = AirbyteTracedException.from_exception(raised_exception)
airbyte_message = traced_exc.as_airbyte_message()

assert type(airbyte_message) == AirbyteMessage
assert isinstance(airbyte_message, AirbyteMessage)
assert airbyte_message.type == MessageType.TRACE
assert airbyte_message.trace.type == TraceType.ERROR
assert airbyte_message.trace.error.message == "Something went wrong in the connector. See the logs for more details."
Expand All @@ -66,7 +66,7 @@ def test_config_error_as_connection_status_message():
traced_exc = AirbyteTracedException("an internal message", message="Config validation error", failure_type=FailureType.config_error)
airbyte_message = traced_exc.as_connection_status_message()

assert type(airbyte_message) == AirbyteMessage
assert isinstance(airbyte_message, AirbyteMessage)
assert airbyte_message.type == MessageType.CONNECTION_STATUS
assert airbyte_message.connectionStatus.status == Status.FAILED
assert airbyte_message.connectionStatus.message == "Config validation error"
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ extend-ignore = [
"E231", # Bad trailing comma (conflicts with Black)
"E501", # line too long (conflicts with Black)
"W503", # line break before binary operator (conflicts with Black)
"E721", # TODO: ella fix after pflake8 version update
"F811", # TODO: ella fix after pflake8 version update
]

Expand Down

0 comments on commit 0c36768

Please sign in to comment.