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 8ecd576de1 Refactor shorter defaults in providers (#34347)
8ecd576de1 is described below

commit 8ecd576de1043dbea40e5e16b5dc34859cc41725
Author: Miroslav Šedivý <[email protected]>
AuthorDate: Thu Sep 14 17:22:39 2023 +0000

    Refactor shorter defaults in providers (#34347)
---
 airflow/providers/amazon/aws/hooks/s3.py                     | 2 +-
 airflow/providers/amazon/aws/operators/datasync.py           | 6 +++---
 airflow/providers/amazon/aws/transfers/azure_blob_to_s3.py   | 2 +-
 airflow/providers/amazon/aws/transfers/gcs_to_s3.py          | 4 ++--
 airflow/providers/apache/pig/hooks/pig.py                    | 2 +-
 airflow/providers/cncf/kubernetes/operators/pod.py           | 2 +-
 airflow/providers/elasticsearch/hooks/elasticsearch.py       | 2 +-
 airflow/providers/google/cloud/hooks/bigquery.py             | 4 ++--
 airflow/providers/google/cloud/hooks/cloud_sql.py            | 4 +---
 airflow/providers/google/cloud/hooks/dataproc_metastore.py   | 2 +-
 airflow/providers/google/cloud/operators/bigquery.py         | 2 +-
 airflow/providers/google/cloud/operators/dataproc.py         | 4 ++--
 airflow/providers/google/cloud/sensors/gcs.py                | 2 +-
 airflow/providers/google/cloud/transfers/mssql_to_gcs.py     | 2 +-
 airflow/providers/google/cloud/transfers/sql_to_gcs.py       | 4 ++--
 airflow/providers/google/cloud/triggers/gcs.py               | 2 +-
 airflow/providers/google/cloud/utils/bigquery.py             | 2 +-
 airflow/providers/google/cloud/utils/dataform.py             | 2 +-
 airflow/providers/grpc/hooks/grpc.py                         | 2 +-
 airflow/providers/hashicorp/_internal_client/vault_client.py | 2 +-
 airflow/providers/oracle/hooks/oracle.py                     | 2 +-
 airflow/providers/redis/log/redis_task_handler.py            | 2 +-
 22 files changed, 28 insertions(+), 30 deletions(-)

diff --git a/airflow/providers/amazon/aws/hooks/s3.py 
b/airflow/providers/amazon/aws/hooks/s3.py
index c3eb5fc52f..0d3b3003bc 100644
--- a/airflow/providers/amazon/aws/hooks/s3.py
+++ b/airflow/providers/amazon/aws/hooks/s3.py
@@ -1375,7 +1375,7 @@ class S3Hook(AwsBaseHook):
                 raise e
 
         if preserve_file_name:
-            local_dir = local_path if local_path else gettempdir()
+            local_dir = local_path or gettempdir()
             subdir = f"airflow_tmp_dir_{uuid4().hex[0:8]}" if 
use_autogenerated_subdir else ""
             filename_in_s3 = s3_obj.key.rsplit("/", 1)[-1]
             file_path = Path(local_dir, subdir, filename_in_s3)
diff --git a/airflow/providers/amazon/aws/operators/datasync.py 
b/airflow/providers/amazon/aws/operators/datasync.py
index 8f3c0ddf72..5688e56c27 100644
--- a/airflow/providers/amazon/aws/operators/datasync.py
+++ b/airflow/providers/amazon/aws/operators/datasync.py
@@ -151,7 +151,7 @@ class DataSyncOperator(BaseOperator):
         self.allow_random_task_choice = allow_random_task_choice
         self.allow_random_location_choice = allow_random_location_choice
 
-        self.create_task_kwargs = create_task_kwargs if create_task_kwargs 
else {}
+        self.create_task_kwargs = create_task_kwargs or {}
         self.create_source_location_kwargs = {}
         if create_source_location_kwargs:
             self.create_source_location_kwargs = create_source_location_kwargs
@@ -159,8 +159,8 @@ class DataSyncOperator(BaseOperator):
         if create_destination_location_kwargs:
             self.create_destination_location_kwargs = 
create_destination_location_kwargs
 
-        self.update_task_kwargs = update_task_kwargs if update_task_kwargs 
else {}
-        self.task_execution_kwargs = task_execution_kwargs if 
task_execution_kwargs else {}
+        self.update_task_kwargs = update_task_kwargs or {}
+        self.task_execution_kwargs = task_execution_kwargs or {}
         self.delete_task_after_execution = delete_task_after_execution
 
         # Validations
diff --git a/airflow/providers/amazon/aws/transfers/azure_blob_to_s3.py 
b/airflow/providers/amazon/aws/transfers/azure_blob_to_s3.py
index ebcd49bdc4..9a7569907f 100644
--- a/airflow/providers/amazon/aws/transfers/azure_blob_to_s3.py
+++ b/airflow/providers/amazon/aws/transfers/azure_blob_to_s3.py
@@ -137,7 +137,7 @@ class AzureBlobStorageToS3Operator(BaseOperator):
             # parent directories/keys
             existing_files = s3_hook.list_keys(bucket_name, prefix=prefix)
             # in case that no files exists, return an empty array to avoid 
errors
-            existing_files = existing_files if existing_files is not None else 
[]
+            existing_files = existing_files or []
             # remove the prefix for the existing files to allow the match
             existing_files = [file.replace(f"{prefix}/", "", 1) for file in 
existing_files]
             files = list(set(files) - set(existing_files))
diff --git a/airflow/providers/amazon/aws/transfers/gcs_to_s3.py 
b/airflow/providers/amazon/aws/transfers/gcs_to_s3.py
index f47eb285ef..b21768b4ab 100644
--- a/airflow/providers/amazon/aws/transfers/gcs_to_s3.py
+++ b/airflow/providers/amazon/aws/transfers/gcs_to_s3.py
@@ -193,12 +193,12 @@ class GCSToS3Operator(BaseOperator):
             # filter all the objects (return empty list) instead of empty
             # prefix returning all the objects
             if prefix:
-                prefix = prefix if prefix.endswith("/") else f"{prefix}/"
+                prefix = prefix.rstrip("/") + "/"
             # look for the bucket and the prefix to avoid look into
             # parent directories/keys
             existing_files = s3_hook.list_keys(bucket_name, prefix=prefix)
             # in case that no files exists, return an empty array to avoid 
errors
-            existing_files = existing_files if existing_files is not None else 
[]
+            existing_files = existing_files or []
             # remove the prefix for the existing files to allow the match
             existing_files = [file.replace(prefix, "", 1) for file in 
existing_files]
             gcs_files = list(set(gcs_files) - set(existing_files))
diff --git a/airflow/providers/apache/pig/hooks/pig.py 
b/airflow/providers/apache/pig/hooks/pig.py
index ca457e9b89..ca6c2f022c 100644
--- a/airflow/providers/apache/pig/hooks/pig.py
+++ b/airflow/providers/apache/pig/hooks/pig.py
@@ -51,7 +51,7 @@ class PigCliHook(BaseHook):
                 " PigOperator. You can also pass ``pig-properties`` in the 
PigCliHook `init`. Currently,"
                 f" the {pig_cli_conn_id} connection has those extras: 
`{conn_pig_properties}`."
             )
-        self.pig_properties = pig_properties if pig_properties else []
+        self.pig_properties = pig_properties or []
         self.conn = conn
         self.sub_process = None
 
diff --git a/airflow/providers/cncf/kubernetes/operators/pod.py 
b/airflow/providers/cncf/kubernetes/operators/pod.py
index 5ec9e2decb..f15cbbe86e 100644
--- a/airflow/providers/cncf/kubernetes/operators/pod.py
+++ b/airflow/providers/cncf/kubernetes/operators/pod.py
@@ -371,7 +371,7 @@ class KubernetesPodOperator(BaseOperator):
         self.get_logs = get_logs
         self.container_logs = container_logs
         if self.container_logs == KubernetesPodOperator.BASE_CONTAINER_NAME:
-            self.container_logs = base_container_name if base_container_name 
else self.BASE_CONTAINER_NAME
+            self.container_logs = base_container_name or 
self.BASE_CONTAINER_NAME
         self.image_pull_policy = image_pull_policy
         self.node_selector = node_selector or {}
         self.annotations = annotations or {}
diff --git a/airflow/providers/elasticsearch/hooks/elasticsearch.py 
b/airflow/providers/elasticsearch/hooks/elasticsearch.py
index 24b8a0f8b0..10801eca2c 100644
--- a/airflow/providers/elasticsearch/hooks/elasticsearch.py
+++ b/airflow/providers/elasticsearch/hooks/elasticsearch.py
@@ -169,7 +169,7 @@ class ElasticsearchPythonHook(BaseHook):
     def __init__(self, hosts: list[Any], es_conn_args: dict | None = None):
         super().__init__()
         self.hosts = hosts
-        self.es_conn_args = es_conn_args if es_conn_args else {}
+        self.es_conn_args = es_conn_args or {}
 
     def _get_elastic_connection(self):
         """Returns the Elasticsearch client."""
diff --git a/airflow/providers/google/cloud/hooks/bigquery.py 
b/airflow/providers/google/cloud/hooks/bigquery.py
index 19bc0fc6f6..9367582493 100644
--- a/airflow/providers/google/cloud/hooks/bigquery.py
+++ b/airflow/providers/google/cloud/hooks/bigquery.py
@@ -123,7 +123,7 @@ class BigQueryHook(GoogleBaseHook, DbApiHook):
         self.location = location
         self.priority = priority
         self.running_job_id: str | None = None
-        self.api_resource_configs: dict = api_resource_configs if 
api_resource_configs else {}
+        self.api_resource_configs: dict = api_resource_configs or {}
         self.labels = labels
         self.credentials_path = "bigquery_hook_credentials.json"
 
@@ -2372,7 +2372,7 @@ class BigQueryBaseCursor(LoggingMixin):
         self.use_legacy_sql = use_legacy_sql
         if api_resource_configs:
             _validate_value("api_resource_configs", api_resource_configs, dict)
-        self.api_resource_configs: dict = api_resource_configs if 
api_resource_configs else {}
+        self.api_resource_configs: dict = api_resource_configs or {}
         self.running_job_id: str | None = None
         self.location = location
         self.num_retries = num_retries
diff --git a/airflow/providers/google/cloud/hooks/cloud_sql.py 
b/airflow/providers/google/cloud/hooks/cloud_sql.py
index 47738fa931..059786f551 100644
--- a/airflow/providers/google/cloud/hooks/cloud_sql.py
+++ b/airflow/providers/google/cloud/hooks/cloud_sql.py
@@ -498,9 +498,7 @@ class CloudSqlProxyRunner(LoggingMixin):
         self.gcp_conn_id = gcp_conn_id
         self.command_line_parameters: list[str] = []
         self.cloud_sql_proxy_socket_directory = self.path_prefix
-        self.sql_proxy_path = (
-            sql_proxy_binary_path if sql_proxy_binary_path else 
self.path_prefix + "_cloud_sql_proxy"
-        )
+        self.sql_proxy_path = sql_proxy_binary_path or 
f"{self.path_prefix}_cloud_sql_proxy"
         self.credentials_path = self.path_prefix + "_credentials.json"
         self._build_command_line_parameters()
 
diff --git a/airflow/providers/google/cloud/hooks/dataproc_metastore.py 
b/airflow/providers/google/cloud/hooks/dataproc_metastore.py
index 8066258fdb..34e954accc 100644
--- a/airflow/providers/google/cloud/hooks/dataproc_metastore.py
+++ b/airflow/providers/google/cloud/hooks/dataproc_metastore.py
@@ -228,7 +228,7 @@ class DataprocMetastoreHook(GoogleBaseHook):
             request={
                 "parent": parent,
                 "service_id": service_id,
-                "service": service if service else {},
+                "service": service or {},
                 "request_id": request_id,
             },
             retry=retry,
diff --git a/airflow/providers/google/cloud/operators/bigquery.py 
b/airflow/providers/google/cloud/operators/bigquery.py
index 1ed333d9dc..f59dff18f5 100644
--- a/airflow/providers/google/cloud/operators/bigquery.py
+++ b/airflow/providers/google/cloud/operators/bigquery.py
@@ -1983,7 +1983,7 @@ class 
BigQueryCreateEmptyDatasetOperator(GoogleCloudBaseOperator):
         self.project_id = project_id
         self.location = location
         self.gcp_conn_id = gcp_conn_id
-        self.dataset_reference = dataset_reference if dataset_reference else {}
+        self.dataset_reference = dataset_reference or {}
         self.impersonation_chain = impersonation_chain
         if exists_ok is not None:
             warnings.warn(
diff --git a/airflow/providers/google/cloud/operators/dataproc.py 
b/airflow/providers/google/cloud/operators/dataproc.py
index dde5baf472..cd604122da 100644
--- a/airflow/providers/google/cloud/operators/dataproc.py
+++ b/airflow/providers/google/cloud/operators/dataproc.py
@@ -1052,10 +1052,10 @@ class DataprocJobBaseOperator(GoogleCloudBaseOperator):
         self.dataproc_jars = dataproc_jars
         self.region = region
 
-        self.job_error_states = job_error_states if job_error_states is not 
None else {"ERROR"}
+        self.job_error_states = job_error_states or {"ERROR"}
         self.impersonation_chain = impersonation_chain
         self.hook = DataprocHook(gcp_conn_id=gcp_conn_id, 
impersonation_chain=impersonation_chain)
-        self.project_id = self.hook.project_id if project_id is None else 
project_id
+        self.project_id = project_id or self.hook.project_id
         self.job_template: DataProcJobBuilder | None = None
         self.job: dict | None = None
         self.dataproc_job_id = None
diff --git a/airflow/providers/google/cloud/sensors/gcs.py 
b/airflow/providers/google/cloud/sensors/gcs.py
index fe3572573a..2fb220ab27 100644
--- a/airflow/providers/google/cloud/sensors/gcs.py
+++ b/airflow/providers/google/cloud/sensors/gcs.py
@@ -421,7 +421,7 @@ class GCSUploadSessionCompleteSensor(BaseSensorOperator):
             raise ValueError("inactivity_period must be non-negative")
         self.inactivity_period = inactivity_period
         self.min_objects = min_objects
-        self.previous_objects = previous_objects if previous_objects else set()
+        self.previous_objects = previous_objects or set()
         self.inactivity_seconds = 0
         self.allow_delete = allow_delete
         self.google_cloud_conn_id = google_cloud_conn_id
diff --git a/airflow/providers/google/cloud/transfers/mssql_to_gcs.py 
b/airflow/providers/google/cloud/transfers/mssql_to_gcs.py
index d9b7282955..892e700704 100644
--- a/airflow/providers/google/cloud/transfers/mssql_to_gcs.py
+++ b/airflow/providers/google/cloud/transfers/mssql_to_gcs.py
@@ -72,7 +72,7 @@ class MSSQLToGCSOperator(BaseSQLToGCSOperator):
     ):
         super().__init__(**kwargs)
         self.mssql_conn_id = mssql_conn_id
-        self.bit_fields = bit_fields if bit_fields else []
+        self.bit_fields = bit_fields or []
 
     def query(self):
         """
diff --git a/airflow/providers/google/cloud/transfers/sql_to_gcs.py 
b/airflow/providers/google/cloud/transfers/sql_to_gcs.py
index c1b90a1bff..05ce03f16d 100644
--- a/airflow/providers/google/cloud/transfers/sql_to_gcs.py
+++ b/airflow/providers/google/cloud/transfers/sql_to_gcs.py
@@ -293,12 +293,12 @@ class BaseSQLToGCSOperator(BaseOperator):
             if self.export_format == "csv":
                 row = self.convert_types(schema, col_type_dict, row)
                 if self.null_marker is not None:
-                    row = [value if value is not None else self.null_marker 
for value in row]
+                    row = [value or self.null_marker for value in row]
                 csv_writer.writerow(row)
             elif self.export_format == "parquet":
                 row = self.convert_types(schema, col_type_dict, row)
                 if self.null_marker is not None:
-                    row = [value if value is not None else self.null_marker 
for value in row]
+                    row = [value or self.null_marker for value in row]
                 rows_buffer.append(row)
                 if len(rows_buffer) >= self.parquet_row_group_size:
                     self._write_rows_to_parquet(parquet_writer, rows_buffer)
diff --git a/airflow/providers/google/cloud/triggers/gcs.py 
b/airflow/providers/google/cloud/triggers/gcs.py
index 8b7f3abe78..a5d181cd05 100644
--- a/airflow/providers/google/cloud/triggers/gcs.py
+++ b/airflow/providers/google/cloud/triggers/gcs.py
@@ -328,7 +328,7 @@ class GCSUploadSessionTrigger(GCSPrefixBlobTrigger):
         )
         self.inactivity_period = inactivity_period
         self.min_objects = min_objects
-        self.previous_objects = previous_objects if previous_objects else set()
+        self.previous_objects = previous_objects or set()
         self.inactivity_seconds = 0.0
         self.allow_delete = allow_delete
         self.last_activity_time: datetime | None = None
diff --git a/airflow/providers/google/cloud/utils/bigquery.py 
b/airflow/providers/google/cloud/utils/bigquery.py
index 76dc9637be..86a88f96e7 100644
--- a/airflow/providers/google/cloud/utils/bigquery.py
+++ b/airflow/providers/google/cloud/utils/bigquery.py
@@ -48,7 +48,7 @@ def convert_job_id(job_id: str | list[str], project_id: str, 
location: str | Non
     :param job_id: Required. The ID of the job.
     :return: str or list[str] of project_id:location:job_id.
     """
-    location = location if location else "US"
+    location = location or "US"
     if isinstance(job_id, list):
         return [f"{project_id}:{location}:{i}" for i in job_id]
     else:
diff --git a/airflow/providers/google/cloud/utils/dataform.py 
b/airflow/providers/google/cloud/utils/dataform.py
index e183e29a1a..743ac06950 100644
--- a/airflow/providers/google/cloud/utils/dataform.py
+++ b/airflow/providers/google/cloud/utils/dataform.py
@@ -153,7 +153,7 @@ def make_initialization_workspace_flow(
         contents=dataform_config_content,
     )
 
-    package_name = package_name if package_name else workspace_id
+    package_name = package_name or workspace_id
     package_json_content = json.dumps(
         {
             "name": package_name,
diff --git a/airflow/providers/grpc/hooks/grpc.py 
b/airflow/providers/grpc/hooks/grpc.py
index b7b0344a4f..843b23bd60 100644
--- a/airflow/providers/grpc/hooks/grpc.py
+++ b/airflow/providers/grpc/hooks/grpc.py
@@ -76,7 +76,7 @@ class GrpcHook(BaseHook):
         self.grpc_conn_id = grpc_conn_id
         self.conn = self.get_connection(self.grpc_conn_id)
         self.extras = self.conn.extra_dejson
-        self.interceptors = interceptors if interceptors else []
+        self.interceptors = interceptors or []
         self.custom_connection_func = custom_connection_func
 
     def get_conn(self) -> grpc.Channel:
diff --git a/airflow/providers/hashicorp/_internal_client/vault_client.py 
b/airflow/providers/hashicorp/_internal_client/vault_client.py
index aea8bfb01d..f8e5c254d4 100644
--- a/airflow/providers/hashicorp/_internal_client/vault_client.py
+++ b/airflow/providers/hashicorp/_internal_client/vault_client.py
@@ -147,7 +147,7 @@ class _VaultClient(LoggingMixin):
             if not radius_secret:
                 raise VaultError("The 'radius' authentication type requires 
'radius_secret'")
 
-        self.kv_engine_version = kv_engine_version if kv_engine_version else 2
+        self.kv_engine_version = kv_engine_version or 2
         self.url = url
         self.auth_type = auth_type
         self.kwargs = kwargs
diff --git a/airflow/providers/oracle/hooks/oracle.py 
b/airflow/providers/oracle/hooks/oracle.py
index bbf98fb405..8e55aab81a 100644
--- a/airflow/providers/oracle/hooks/oracle.py
+++ b/airflow/providers/oracle/hooks/oracle.py
@@ -340,7 +340,7 @@ class OracleHook(DbApiHook):
         if self.supports_autocommit:
             self.set_autocommit(conn, False)
         cursor = conn.cursor()  # type: ignore[attr-defined]
-        values_base = target_fields if target_fields else rows[0]
+        values_base = target_fields or rows[0]
         prepared_stm = "insert into {tablename} {columns} values 
({values})".format(
             tablename=table,
             columns="({})".format(", ".join(target_fields)) if target_fields 
else "",
diff --git a/airflow/providers/redis/log/redis_task_handler.py 
b/airflow/providers/redis/log/redis_task_handler.py
index 2befdadbe7..2582faf4ed 100644
--- a/airflow/providers/redis/log/redis_task_handler.py
+++ b/airflow/providers/redis/log/redis_task_handler.py
@@ -64,7 +64,7 @@ class RedisTaskHandler(FileTaskHandler, LoggingMixin):
         self.handler: _RedisHandler | None = None
         self.max_lines = max_lines
         self.ttl_seconds = ttl_seconds
-        self.conn_id = conn_id if conn_id is not None else conf.get("logging", 
"REMOTE_LOG_CONN_ID")
+        self.conn_id = conn_id or conf.get("logging", "REMOTE_LOG_CONN_ID")
 
     @cached_property
     def conn(self):

Reply via email to