Skip to content

Commit

Permalink
Refactor: Simplify code in providers/alibaba (#33225)
Browse files Browse the repository at this point in the history
  • Loading branch information
eumiro committed Aug 8, 2023
1 parent cd7e7bc commit 4e83660
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions airflow/providers/alibaba/cloud/hooks/analyticdb_spark.py
Expand Up @@ -306,7 +306,7 @@ def _validate_list_of_stringables(vals: Sequence[str | int | float]) -> bool:
if (
vals is None
or not isinstance(vals, (tuple, list))
or any(1 for val in vals if not isinstance(val, (str, int, float)))
or not all(isinstance(val, (str, int, float)) for val in vals)
):
raise ValueError("List of strings expected")
return True
Expand All @@ -321,7 +321,7 @@ def _validate_extra_conf(conf: dict[Any, Any]) -> bool:
if conf:
if not isinstance(conf, dict):
raise ValueError("'conf' argument must be a dict")
if any(True for k, v in conf.items() if not (v and isinstance(v, str) or isinstance(v, int))):
if not all(v and isinstance(v, str) or isinstance(v, int) for v in conf.values()):
raise ValueError("'conf' values must be either strings or ints")
return True

Expand Down
2 changes: 1 addition & 1 deletion airflow/providers/alibaba/cloud/hooks/oss.py
Expand Up @@ -66,7 +66,7 @@ def get_key() -> str:
raise ValueError("Missing key parameter!")

key_name = get_key()
if "bucket_name" not in bound_args.arguments or bound_args.arguments["bucket_name"] is None:
if bound_args.arguments.get("bucket_name") is None:
bound_args.arguments["bucket_name"], bound_args.arguments["key"] = OSSHook.parse_oss_url(
bound_args.arguments[key_name]
)
Expand Down
3 changes: 1 addition & 2 deletions airflow/providers/alibaba/cloud/sensors/oss_key.py
Expand Up @@ -69,14 +69,13 @@ def poke(self, context: Context):
:param context: the context of the object
:returns: True if the object exists, False otherwise
"""
parsed_url = urlsplit(self.bucket_key)
if self.bucket_name is None:
parsed_url = urlsplit(self.bucket_key)
if parsed_url.netloc == "":
raise AirflowException("If key is a relative path from root, please provide a bucket_name")
self.bucket_name = parsed_url.netloc
self.bucket_key = parsed_url.path.lstrip("/")
else:
parsed_url = urlsplit(self.bucket_key)
if parsed_url.scheme != "" or parsed_url.netloc != "":
raise AirflowException(
"If bucket_name is provided, bucket_key"
Expand Down

0 comments on commit 4e83660

Please sign in to comment.