This is an automated email from the ASF dual-hosted git repository.
potiuk 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 d747a7924b Refactor str.startswith with tuples (#33292)
d747a7924b is described below
commit d747a7924bca4b1e44003fe0932c28d7b504b088
Author: Miroslav Šedivý <[email protected]>
AuthorDate: Wed Aug 16 09:03:57 2023 +0000
Refactor str.startswith with tuples (#33292)
---
airflow/template/templater.py | 6 +++---
dev/chart/build_changelog_annotations.py | 2 +-
scripts/ci/pre_commit/pre_commit_update_providers_dependencies.py | 4 ++--
scripts/in_container/run_provider_yaml_files_check.py | 7 +++----
scripts/in_container/verify_providers.py | 6 +++---
setup.py | 2 +-
6 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/airflow/template/templater.py b/airflow/template/templater.py
index 2d2033696b..19eb3f5996 100644
--- a/airflow/template/templater.py
+++ b/airflow/template/templater.py
@@ -70,7 +70,7 @@ class Templater(LoggingMixin):
content = getattr(self, field, None)
if content is None:
continue
- elif isinstance(content, str) and any(content.endswith(ext)
for ext in self.template_ext):
+ elif isinstance(content, str) and
content.endswith(tuple(self.template_ext)):
env = self.get_template_env()
try:
setattr(self, field, env.loader.get_source(env,
content)[0]) # type: ignore
@@ -79,7 +79,7 @@ class Templater(LoggingMixin):
elif isinstance(content, list):
env = self.get_template_env()
for i, item in enumerate(content):
- if isinstance(item, str) and any(item.endswith(ext)
for ext in self.template_ext):
+ if isinstance(item, str) and
item.endswith(tuple(self.template_ext)):
try:
content[i] = env.loader.get_source(env,
item)[0] # type: ignore
except Exception:
@@ -150,7 +150,7 @@ class Templater(LoggingMixin):
jinja_env = self.get_template_env()
if isinstance(value, str):
- if any(value.endswith(ext) for ext in self.template_ext): # A
filepath.
+ if value.endswith(tuple(self.template_ext)): # A filepath.
template = jinja_env.get_template(value)
else:
template = jinja_env.from_string(value)
diff --git a/dev/chart/build_changelog_annotations.py
b/dev/chart/build_changelog_annotations.py
index 259bd7dac4..fc38a47dcb 100755
--- a/dev/chart/build_changelog_annotations.py
+++ b/dev/chart/build_changelog_annotations.py
@@ -96,7 +96,7 @@ with open("chart/RELEASE_NOTES.rst") as f:
break
in_first_release = True
continue
- if line.startswith('"""') or line.startswith("----") or
line.startswith("^^^^"):
+ if line.startswith(('"""', "----", "^^^^")):
continue
# Make sure we get past "significant features" before we actually
start keeping track
diff --git a/scripts/ci/pre_commit/pre_commit_update_providers_dependencies.py
b/scripts/ci/pre_commit/pre_commit_update_providers_dependencies.py
index 0c489bad63..508ca72abe 100755
--- a/scripts/ci/pre_commit/pre_commit_update_providers_dependencies.py
+++ b/scripts/ci/pre_commit/pre_commit_update_providers_dependencies.py
@@ -126,7 +126,7 @@ def get_provider_id_from_import(import_name: str,
file_path: Path) -> str | None
provider_id =
get_provider_id_from_relative_import_or_file(relative_provider_import)
if provider_id is None:
relative_path_from_import = relative_provider_import.replace(".",
os.sep)
- if any(relative_path_from_import.startswith(suspended_path) for
suspended_path in suspended_paths):
+ if relative_path_from_import.startswith(tuple(suspended_paths)):
return None
warnings.append(f"We could not determine provider id from import
{import_name} in {file_path}")
return provider_id
@@ -154,7 +154,7 @@ def get_provider_id_from_file_name(file_path: Path) -> str
| None:
return None
provider_id =
get_provider_id_from_relative_import_or_file(str(relative_path))
if provider_id is None and file_path.name not in ["__init__.py",
"get_provider_info.py"]:
- if any(relative_path.as_posix().startswith(suspended_path) for
suspended_path in suspended_paths):
+ if relative_path.as_posix().startswith(tuple(suspended_paths)):
return None
else:
warnings.append(f"We had a problem to classify the file
{file_path} to a provider")
diff --git a/scripts/in_container/run_provider_yaml_files_check.py
b/scripts/in_container/run_provider_yaml_files_check.py
index e2caeea93b..ae523eb4ba 100755
--- a/scripts/in_container/run_provider_yaml_files_check.py
+++ b/scripts/in_container/run_provider_yaml_files_check.py
@@ -419,19 +419,18 @@ def check_doc_files(yaml_files: dict[str, dict]):
for f in expected_doc_files
if f.name != "index.rst"
and "_partials" not in f.parts
- and not any(f.relative_to(DOCS_DIR).as_posix().startswith(s) for s in
suspended_providers)
+ and not
f.relative_to(DOCS_DIR).as_posix().startswith(tuple(suspended_providers))
} | {
f"/docs/{f.relative_to(DOCS_DIR).as_posix()}"
for f in DOCS_DIR.glob("apache-airflow-providers-*/operators.rst")
- if not any(f.relative_to(DOCS_DIR).as_posix().startswith(s) for s in
suspended_providers)
+ if not
f.relative_to(DOCS_DIR).as_posix().startswith(tuple(suspended_providers))
}
console.print("[yellow]Suspended logos:[/]")
console.print(suspended_logos)
expected_logo_urls = {
f"/{f.relative_to(DOCS_DIR).as_posix()}"
for f in DOCS_DIR.glob("integration-logos/**/*")
- if f.is_file()
- and not any(f"/{f.relative_to(DOCS_DIR).as_posix()}".startswith(s) for
s in suspended_logos)
+ if f.is_file() and not
f"/{f.relative_to(DOCS_DIR).as_posix()}".startswith(tuple(suspended_logos))
}
try:
diff --git a/scripts/in_container/verify_providers.py
b/scripts/in_container/verify_providers.py
index 6df9f9900f..e6f6fa140a 100755
--- a/scripts/in_container/verify_providers.py
+++ b/scripts/in_container/verify_providers.py
@@ -170,9 +170,9 @@ def import_all_classes(
return f"{prefix}{provider_id}"
if provider_ids:
- provider_prefixes = [mk_prefix(provider_id) for provider_id in
provider_ids]
+ provider_prefixes = tuple(mk_prefix(provider_id) for provider_id in
provider_ids)
else:
- provider_prefixes = [prefix]
+ provider_prefixes = (prefix,)
def onerror(_):
nonlocal tracebacks
@@ -187,7 +187,7 @@ def import_all_classes(
for path, prefix in walkable_paths_and_prefixes.items():
for modinfo in pkgutil.walk_packages(path=[path], prefix=prefix,
onerror=onerror):
- if not modinfo.name.startswith(tuple(provider_prefixes)):
+ if not modinfo.name.startswith(provider_prefixes):
if print_skips:
console.print(f"Skipping module: {modinfo.name}")
continue
diff --git a/setup.py b/setup.py
index 7dc2e9f6eb..9dd5ecbf8f 100644
--- a/setup.py
+++ b/setup.py
@@ -710,7 +710,7 @@ def is_package_excluded(package: str, exclusion_list:
list[str]) -> bool:
:param exclusion_list: list of excluded packages
:return: true if package should be excluded
"""
- return any(package.startswith(excluded_package) for excluded_package in
exclusion_list)
+ return package.startswith(tuple(exclusion_list))
def remove_provider_limits(package: str) -> str: