This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new fa5e54c4c5 Combine similar if logics in providers (#33987)
fa5e54c4c5 is described below
commit fa5e54c4c57631de353102af56633f05346685f9
Author: Hussein Awala <[email protected]>
AuthorDate: Sun Sep 3 22:09:07 2023 +0200
Combine similar if logics in providers (#33987)
---
airflow/providers/amazon/aws/utils/sqs.py | 4 +---
airflow/providers/celery/executors/celery_executor.py | 4 +---
airflow/providers/cncf/kubernetes/operators/pod.py | 8 ++------
airflow/providers/google/cloud/log/gcs_task_handler.py | 6 +++---
airflow/providers/google/cloud/transfers/cassandra_to_gcs.py | 4 +---
airflow/providers/oracle/hooks/oracle.py | 4 +---
6 files changed, 9 insertions(+), 21 deletions(-)
diff --git a/airflow/providers/amazon/aws/utils/sqs.py
b/airflow/providers/amazon/aws/utils/sqs.py
index 0ae5e7ac98..078baa2748 100644
--- a/airflow/providers/amazon/aws/utils/sqs.py
+++ b/airflow/providers/amazon/aws/utils/sqs.py
@@ -38,9 +38,7 @@ def process_response(
:param response: The response from SQS
:return: The processed response
"""
- if not isinstance(response, dict):
- return []
- elif "Messages" not in response:
+ if not isinstance(response, dict) or "Messages" not in response:
return []
messages = response["Messages"]
diff --git a/airflow/providers/celery/executors/celery_executor.py
b/airflow/providers/celery/executors/celery_executor.py
index a73e7dbb73..a2caf92c75 100644
--- a/airflow/providers/celery/executors/celery_executor.py
+++ b/airflow/providers/celery/executors/celery_executor.py
@@ -368,9 +368,7 @@ class CeleryExecutor(BaseExecutor):
self.success(key, info)
elif state in (celery_states.FAILURE, celery_states.REVOKED):
self.fail(key, info)
- elif state == celery_states.STARTED:
- pass
- elif state == celery_states.PENDING:
+ elif state in (celery_states.STARTEDstate, celery_states.PENDING):
pass
else:
self.log.info("Unexpected state for %s: %s", key, state)
diff --git a/airflow/providers/cncf/kubernetes/operators/pod.py
b/airflow/providers/cncf/kubernetes/operators/pod.py
index 122315fe40..3f3438b1b7 100644
--- a/airflow/providers/cncf/kubernetes/operators/pod.py
+++ b/airflow/providers/cncf/kubernetes/operators/pod.py
@@ -1003,14 +1003,10 @@ class _optionally_suppress(AbstractContextManager):
def __exit__(self, exctype, excinst, exctb):
error = exctype is not None
matching_error = error and issubclass(exctype, self._exceptions)
- if error and not matching_error:
- return False
- elif matching_error and self.reraise:
+ if (error and not matching_error) or (matching_error and self.reraise):
return False
elif matching_error:
self.exception = excinst
logger = logging.getLogger(__name__)
logger.exception(excinst)
- return True
- else:
- return True
+ return True
diff --git a/airflow/providers/google/cloud/log/gcs_task_handler.py
b/airflow/providers/google/cloud/log/gcs_task_handler.py
index e6c8b1833f..cebe9a829e 100644
--- a/airflow/providers/google/cloud/log/gcs_task_handler.py
+++ b/airflow/providers/google/cloud/log/gcs_task_handler.py
@@ -263,8 +263,8 @@ class GCSTaskHandler(FileTaskHandler, LoggingMixin):
:meta private:
"""
- if exc.args and isinstance(exc.args[0], str) and "No such object" in
exc.args[0]:
- return True
- elif getattr(exc, "resp", {}).get("status") == "404":
+ if (exc.args and isinstance(exc.args[0], str) and "No such object" in
exc.args[0]) or getattr(
+ exc, "resp", {}
+ ).get("status") == "404":
return True
return False
diff --git a/airflow/providers/google/cloud/transfers/cassandra_to_gcs.py
b/airflow/providers/google/cloud/transfers/cassandra_to_gcs.py
index 620edfbe15..8c53b929f4 100644
--- a/airflow/providers/google/cloud/transfers/cassandra_to_gcs.py
+++ b/airflow/providers/google/cloud/transfers/cassandra_to_gcs.py
@@ -258,9 +258,7 @@ class CassandraToGCSOperator(BaseOperator):
def convert_value(self, value: Any | None) -> Any | None:
"""Convert value to BQ type."""
- if not value:
- return value
- elif isinstance(value, (str, int, float, bool, dict)):
+ if not value or isinstance(value, (str, int, float, bool, dict)):
return value
elif isinstance(value, bytes):
return b64encode(value).decode("ascii")
diff --git a/airflow/providers/oracle/hooks/oracle.py
b/airflow/providers/oracle/hooks/oracle.py
index d91bccecc0..2b6bfdb009 100644
--- a/airflow/providers/oracle/hooks/oracle.py
+++ b/airflow/providers/oracle/hooks/oracle.py
@@ -295,9 +295,7 @@ class OracleHook(DbApiHook):
for cell in row:
if isinstance(cell, str):
lst.append("'" + str(cell).replace("'", "''") + "'")
- elif cell is None:
- lst.append("NULL")
- elif isinstance(cell, float) and math.isnan(cell): # coerce
numpy NaN to NULL
+ elif cell is None or isinstance(cell, float) and
math.isnan(cell): # coerce numpy NaN to NULL
lst.append("NULL")
elif numpy and isinstance(cell, numpy.datetime64):
lst.append("'" + str(cell) + "'")