Skip to content

Commit

Permalink
Simplify conditions on len() in providers/microsoft (#33566)
Browse files Browse the repository at this point in the history
  • Loading branch information
eumiro committed Aug 21, 2023
1 parent a1e6cd4 commit b43fcae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions airflow/providers/microsoft/azure/hooks/cosmos.py
Expand Up @@ -153,7 +153,7 @@ def does_collection_exist(self, collection_name: str, database_name: str) -> boo
parameters=[json.dumps({"name": "@id", "value": collection_name})],
)
)
if len(existing_container) == 0:
if not existing_container:
return False

return True
Expand All @@ -180,7 +180,7 @@ def create_collection(
)

# Only create if we did not find it already existing
if len(existing_container) == 0:
if not existing_container:
self.get_conn().get_database_client(self.__get_database_name(database_name)).create_container(
collection_name, partition_key=partition_key
)
Expand All @@ -196,7 +196,7 @@ def does_database_exist(self, database_name: str) -> bool:
parameters=[json.dumps({"name": "@id", "value": database_name})],
)
)
if len(existing_database) == 0:
if not existing_database:
return False

return True
Expand All @@ -216,7 +216,7 @@ def create_database(self, database_name: str) -> None:
)

# Only create if we did not find it already existing
if len(existing_database) == 0:
if not existing_database:
self.get_conn().create_database(database_name)

def delete_database(self, database_name: str) -> None:
Expand Down
6 changes: 3 additions & 3 deletions airflow/providers/microsoft/azure/hooks/wasb.py
Expand Up @@ -241,7 +241,7 @@ def check_for_prefix(self, container_name: str, prefix: str, **kwargs) -> bool:
:return: True if blobs matching the prefix exist, False otherwise.
"""
blobs = self.get_blobs_list(container_name=container_name, prefix=prefix, **kwargs)
return len(blobs) > 0
return bool(blobs)

def get_blobs_list(
self,
Expand Down Expand Up @@ -502,7 +502,7 @@ def delete_file(
blobs_to_delete = [blob_name]
else:
blobs_to_delete = []
if not ignore_if_missing and len(blobs_to_delete) == 0:
if not ignore_if_missing and not blobs_to_delete:
raise AirflowException(f"Blob(s) not found: {blob_name}")

# The maximum number of blobs that can be deleted in a single request is 256 using the underlying
Expand Down Expand Up @@ -683,4 +683,4 @@ async def check_for_prefix_async(self, container_name: str, prefix: str, **kwarg
:param kwargs: Optional keyword arguments for ``ContainerClient.walk_blobs``
"""
blobs = await self.get_blobs_list_async(container_name=container_name, prefix=prefix, **kwargs)
return len(blobs) > 0
return bool(blobs)

0 comments on commit b43fcae

Please sign in to comment.