This is an automated email from the ASF dual-hosted git repository.
uranusjr 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 b4d4f55b47 Refactor: Replace lambdas with comprehensions in providers
(#33771)
b4d4f55b47 is described below
commit b4d4f55b479d07c13ab25bb2e80cb053378b56d7
Author: Miroslav Šedivý <[email protected]>
AuthorDate: Thu Aug 31 08:47:45 2023 +0000
Refactor: Replace lambdas with comprehensions in providers (#33771)
Co-authored-by: Tzu-ping Chung <[email protected]>
---
airflow/providers/amazon/aws/transfers/ftp_to_s3.py | 2 +-
airflow/providers/openlineage/extractors/manager.py | 18 +++++++-----------
airflow/providers/slack/transfers/sql_to_slack.py | 2 +-
3 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/airflow/providers/amazon/aws/transfers/ftp_to_s3.py
b/airflow/providers/amazon/aws/transfers/ftp_to_s3.py
index e13c98605d..7ec4fd192e 100644
--- a/airflow/providers/amazon/aws/transfers/ftp_to_s3.py
+++ b/airflow/providers/amazon/aws/transfers/ftp_to_s3.py
@@ -127,7 +127,7 @@ class FTPToS3Operator(BaseOperator):
files = list_dir
else:
ftp_filename: str = self.ftp_filenames
- files = list(filter(lambda f: ftp_filename in f, list_dir))
+ files = [f for f in list_dir if ftp_filename in f]
for file in files:
self.log.info("Moving file %s", file)
diff --git a/airflow/providers/openlineage/extractors/manager.py
b/airflow/providers/openlineage/extractors/manager.py
index 02a4124840..17a8923f5b 100644
--- a/airflow/providers/openlineage/extractors/manager.py
+++ b/airflow/providers/openlineage/extractors/manager.py
@@ -18,7 +18,7 @@ from __future__ import annotations
import os
from contextlib import suppress
-from typing import TYPE_CHECKING
+from typing import TYPE_CHECKING, Iterator
from airflow.configuration import conf
from airflow.providers.openlineage.extractors import BaseExtractor,
OperatorLineage
@@ -42,15 +42,11 @@ def try_import_from_string(string):
return import_string(string)
-_extractors: list[type[BaseExtractor]] = list(
- filter(
- lambda t: t is not None,
- [
- PythonExtractor,
- BashExtractor,
- ],
- )
-)
+def _iter_extractor_types() -> Iterator[type[BaseExtractor]]:
+ if PythonExtractor is not None:
+ yield PythonExtractor
+ if BashExtractor is not None:
+ yield BashExtractor
class ExtractorManager(LoggingMixin):
@@ -63,7 +59,7 @@ class ExtractorManager(LoggingMixin):
# Comma-separated extractors in OPENLINEAGE_EXTRACTORS variable.
# Extractors should implement BaseExtractor
- for extractor in _extractors:
+ for extractor in _iter_extractor_types():
for operator_class in extractor.get_operator_classnames():
self.extractors[operator_class] = extractor
diff --git a/airflow/providers/slack/transfers/sql_to_slack.py
b/airflow/providers/slack/transfers/sql_to_slack.py
index aa152d4dc0..213a9026d4 100644
--- a/airflow/providers/slack/transfers/sql_to_slack.py
+++ b/airflow/providers/slack/transfers/sql_to_slack.py
@@ -153,7 +153,7 @@ class SqlToSlackOperator(BaseSqlToSlackOperator):
# If this is the first render of the template fields, exclude
slack_message from rendering since
# the SQL results haven't been retrieved yet.
if self.times_rendered == 0:
- fields_to_render: Iterable[str] = filter(lambda x: x !=
"slack_message", self.template_fields)
+ fields_to_render: Iterable[str] = (x for x in self.template_fields
if x != "slack_message")
else:
fields_to_render = self.template_fields