Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Replace lambdas with comprehensions #33745

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions airflow/utils/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,14 @@ def infer_time_unit(time_seconds_arr: Collection[float]) -> TimeUnit:
def scale_time_units(time_seconds_arr: Collection[float], unit: TimeUnit) -> Collection[float]:
"""Convert an array of time durations in seconds to the specified time unit."""
if unit == "minutes":
return [x / 60 for x in time_seconds_arr]
factor = 60
elif unit == "hours":
return [x / (60 * 60) for x in time_seconds_arr]
factor = 60 * 60
elif unit == "days":
return [x / (24 * 60 * 60) for x in time_seconds_arr]
return time_seconds_arr
factor = 24 * 60 * 60
else:
factor = 1
return [x / factor for x in time_seconds_arr]


def days_ago(n, hour=0, minute=0, second=0, microsecond=0):
Expand Down
2 changes: 1 addition & 1 deletion dev/assign_cherry_picked_prs_with_milestone.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def assign_prs(
output_folder: str,
):
changes = get_changes(verbose, previous_release, current_release)
changes = list(filter(lambda change: change.pr is not None, changes))
changes = [change for change in changes if change.pr is not None]
prs = [change.pr for change in changes]

g = Github(github_token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ class ProviderPRInfo(NamedTuple):
)
continue
prs = get_prs_for_package(package_id)
provider_prs[package_id] = list(filter(lambda pr: pr not in excluded_prs, prs))
provider_prs[package_id] = [pr for pr in prs if pr not in excluded_prs]
all_prs.update(provider_prs[package_id])
g = Github(github_token)
repo = g.get_repo("apache/airflow")
Expand Down
2 changes: 1 addition & 1 deletion dev/breeze/src/airflow_breeze/utils/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def get_active_airflow_versions(confirm: bool = True) -> list[str]:
match = ACTIVE_TAG_MATCH.match(tag)
if match and match.group(1) == "2":
all_active_tags.append(tag)
airflow_versions = sorted(all_active_tags, key=lambda x: Version(x))
airflow_versions = sorted(all_active_tags, key=Version)
if confirm:
get_console().print(f"All Airflow 2 versions: {all_active_tags}")
answer = user_confirm(
Expand Down
2 changes: 1 addition & 1 deletion dev/breeze/src/airflow_breeze/utils/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def print_async_summary(completed_list: list[ApplyResult]) -> None:

def get_completed_result_list(results: list[ApplyResult]) -> list[ApplyResult]:
"""Return completed results from the list."""
return list(filter(lambda result: result.ready(), results))
return [result for result in results if result.ready()]


class SummarizeAfter(Enum):
Expand Down
16 changes: 7 additions & 9 deletions dev/example_dags/update_example_dags_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,17 @@ def find_matches(_file: Path, provider: str, version: str):

if __name__ == "__main__":
curdir: Path = Path(os.curdir).resolve()
dirs: list[Path] = list(filter(os.path.isdir, curdir.iterdir()))
dirs: list[Path] = [p for p in curdir.iterdir() if p.is_dir()]
with Progress(console=console) as progress:
task = progress.add_task(f"Updating {len(dirs)}", total=len(dirs))
for directory in dirs:
if directory.name.startswith("apache-airflow-providers-"):
provider = directory.name[len("apache-airflow-providers-") :]
console.print(f"[bright_blue] Processing {directory}")
version_dirs = list(filter(os.path.isdir, directory.iterdir()))
for version_dir in version_dirs:
version = version_dir.name
console.print(version)
for file in version_dir.rglob("*.html"):
candidate_file = file
if candidate_file.exists():
find_matches(candidate_file, provider, version)
for version_dir in directory.iterdir():
if version_dir.is_dir():
console.print(version_dir.name)
for candidate_file in version_dir.rglob("*.html"):
if candidate_file.exists():
find_matches(candidate_file, provider, version_dir.name)
progress.advance(task)
4 changes: 2 additions & 2 deletions kubernetes_tests/test_kubernetes_pod_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def kubeconfig_path():

@pytest.fixture
def test_label(request):
label = "".join(filter(str.isalnum, f"{request.node.cls.__name__}.{request.node.name}")).lower()
label = "".join(c for c in f"{request.node.cls.__name__}.{request.node.name}" if c.isalnum()).lower()
return label[-63:]


Expand Down Expand Up @@ -284,7 +284,7 @@ def test_already_checked_on_failure(self, mock_get_connection):
k.execute(context)
actual_pod = k.find_pod("default", context, exclude_checked=False)
actual_pod = self.api_client.sanitize_for_serialization(actual_pod)
status = next(iter(filter(lambda x: x["name"] == "base", actual_pod["status"]["containerStatuses"])))
status = next(x for x in actual_pod["status"]["containerStatuses"] if x["name"] == "base")
assert status["state"]["terminated"]["reason"] == "Error"
assert actual_pod["metadata"]["labels"]["already_checked"] == "True"

Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,7 @@ def get_all_db_dependencies() -> list[str]:
# to separately add providers dependencies - they have been already added as 'providers' extras above
_all_dependencies = get_unique_dependency_list(EXTRAS_DEPENDENCIES.values())

_all_dependencies_without_airflow_providers = list(
filter(lambda k: "apache-airflow-" not in k, _all_dependencies)
)
_all_dependencies_without_airflow_providers = [k for k in _all_dependencies if "apache-airflow-" not in k]

# All user extras here
# all is purely development extra and it should contain only direct dependencies of Airflow
Expand Down