Skip to content

Commit

Permalink
Simplify conditions on len()
Browse files Browse the repository at this point in the history
  • Loading branch information
eumiro committed Aug 21, 2023
1 parent 82c3e2d commit abf2129
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion airflow/cli/commands/pool_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def pool_import(args):
if not os.path.exists(args.file):
raise SystemExit(f"Missing pools file {args.file}")
pools, failed = pool_import_helper(args.file)
if len(failed) > 0:
if failed:
raise SystemExit(f"Failed to update pool(s): {', '.join(failed)}")
print(f"Uploaded {len(pools)} pool(s)")

Expand Down
2 changes: 1 addition & 1 deletion airflow/cli/commands/webserver_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _get_num_ready_workers_running(self) -> int:
def ready_prefix_on_cmdline(proc):
try:
cmdline = proc.cmdline()
if len(cmdline) > 0:
if cmdline:
return settings.GUNICORN_WORKER_READY_PREFIX in cmdline[0]
except psutil.NoSuchProcess:
pass
Expand Down
2 changes: 1 addition & 1 deletion airflow/dag_processing/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ def process_file(
Stats.incr("dag_file_refresh_error", 1, 1, tags={"file_path": file_path})
return 0, 0

if len(dagbag.dags) > 0:
if dagbag.dags:
self.log.info("DAG(s) %s retrieved from %s", dagbag.dags.keys(), file_path)
else:
self.log.warning("No viable dags retrieved from %s", file_path)
Expand Down
2 changes: 1 addition & 1 deletion airflow/listeners/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self):

@property
def has_listeners(self) -> bool:
return len(self.pm.get_plugins()) > 0
return bool(self.pm.get_plugins())

@property
def hook(self) -> _HookRelay:
Expand Down
2 changes: 1 addition & 1 deletion airflow/models/baseoperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def apply_defaults(self: BaseOperator, *args: Any, **kwargs: Any) -> Any:
from airflow.models.dag import DagContext
from airflow.utils.task_group import TaskGroupContext

if len(args) > 0:
if args:
raise AirflowException("Use keyword arguments when initializing operators")

instantiated_from_mapped = kwargs.pop(
Expand Down
4 changes: 2 additions & 2 deletions airflow/models/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ def get_task_instances_before(
.limit(num)
).all()

if len(execution_dates) == 0:
if not execution_dates:
return self.get_task_instances(start_date=base_date, end_date=base_date, session=session)

min_date: datetime | None = execution_dates[-1]._mapping.get(
Expand Down Expand Up @@ -3146,7 +3146,7 @@ def deactivate_unknown_dags(active_dag_ids, session=NEW_SESSION):
:param active_dag_ids: list of DAG IDs that are active
:return: None
"""
if len(active_dag_ids) == 0:
if not active_dag_ids:
return
for dag in session.scalars(select(DagModel).where(~DagModel.dag_id.in_(active_dag_ids))).all():
dag.is_active = False
Expand Down
2 changes: 1 addition & 1 deletion airflow/sensors/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ def poke(self, context: Context):
return True

for _, _, files in os.walk(path):
if len(files) > 0:
if files:
return True
return False
2 changes: 1 addition & 1 deletion airflow/triggers/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ async def run(self) -> typing.AsyncIterator[TriggerEvent]:
self.log.info("Found File %s last modified: %s", str(path), str(mod_time))
yield TriggerEvent(True)
for _, _, files in os.walk(self.filepath):
if len(files) > 0:
if files:
yield TriggerEvent(True)
await asyncio.sleep(self.poll_interval)
2 changes: 1 addition & 1 deletion airflow/www/extensions/init_jinja_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def prepare_jinja_globals():
}

backends = conf.get("api", "auth_backends")
if len(backends) > 0 and backends[0] != "airflow.api.auth.backend.deny_all":
if backends and backends[0] != "airflow.api.auth.backend.deny_all":
extra_globals["rest_api_enabled"] = True

if "analytics_tool" in conf.getsection("webserver"):
Expand Down
6 changes: 3 additions & 3 deletions airflow/www/fab_security/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def _search_ldap(self, ldap, con, username):
self.auth_ldap_lastname_field,
self.auth_ldap_email_field,
]
if len(self.auth_roles_mapping) > 0:
if self.auth_roles_mapping:
request_fields.append(self.auth_ldap_group_field)

# perform the LDAP search
Expand Down Expand Up @@ -561,7 +561,7 @@ def _ldap_calculate_user_roles(self, user_attributes: dict[str, list[bytes]]) ->
user_role_objects = set()

# apply AUTH_ROLES_MAPPING
if len(self.auth_roles_mapping) > 0:
if self.auth_roles_mapping:
user_role_keys = self.ldap_extract_list(user_attributes, self.auth_ldap_group_field)
user_role_objects.update(self.get_roles_from_keys(user_role_keys))

Expand Down Expand Up @@ -852,7 +852,7 @@ def _oauth_calculate_user_roles(self, userinfo) -> list[str]:
user_role_objects = set()

# apply AUTH_ROLES_MAPPING
if len(self.auth_roles_mapping) > 0:
if self.auth_roles_mapping:
user_role_keys = userinfo.get("role_keys", [])
user_role_objects.update(self.get_roles_from_keys(user_role_keys))

Expand Down
2 changes: 1 addition & 1 deletion airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3857,7 +3857,7 @@ def dataset_dependencies(self):

for dag, dependencies in SerializedDagModel.get_dag_dependencies().items():
dag_node_id = f"dag:{dag}"
if dag_node_id not in nodes_dict and len(dependencies) > 0:
if dag_node_id not in nodes_dict:
for dep in dependencies:
if dep.dependency_type == "dag" or dep.dependency_type == "dataset":
nodes_dict[dag_node_id] = node_dict(dag_node_id, dag, "dag")
Expand Down
2 changes: 1 addition & 1 deletion dev/breeze/src/airflow_breeze/utils/coertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def coerce_bool_value(value: str | bool) -> bool:


def one_or_none_set(iterable: Iterable[bool]) -> bool:
return sum(1 for i in iterable if i) in (0, 1)
return 0 <= sum(1 for i in iterable if i) <= 1

0 comments on commit abf2129

Please sign in to comment.