diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9c45ad4de5fc4..efe07c7ea8c28 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -903,7 +903,7 @@ repos: stages: ['manual'] name: Run mypy for dev (manual) language: python - entry: ./scripts/ci/prek/mypy_folder.py dev + entry: ./scripts/ci/prek/mypy_folder.py dev scripts pass_filenames: false files: ^.*\.py$ require_serial: true diff --git a/scripts/ci/prek/check_secrets_search_path_sync.py b/scripts/ci/prek/check_secrets_search_path_sync.py index d6152f7152407..a5bcb1a76cae1 100755 --- a/scripts/ci/prek/check_secrets_search_path_sync.py +++ b/scripts/ci/prek/check_secrets_search_path_sync.py @@ -21,6 +21,7 @@ import ast import sys from pathlib import Path +from types import EllipsisType AIRFLOW_ROOT = Path(__file__).parents[3].resolve() CORE_SECRETS_FILE = AIRFLOW_ROOT / "airflow-core" / "src" / "airflow" / "secrets" / "base_secrets.py" @@ -29,7 +30,9 @@ ) -def extract_from_file(file_path: Path, constant_name: str) -> list[str] | None: +def extract_from_file( + file_path: Path, constant_name: str +) -> list[str | bytes | int | float | complex | EllipsisType | None] | None: """Extract a list constant value from a Python file using AST parsing.""" try: with open(file_path) as f: diff --git a/scripts/ci/prek/check_shared_distributions_usage.py b/scripts/ci/prek/check_shared_distributions_usage.py index 7fb7fe6d4fef7..c9cd41e92dcb1 100755 --- a/scripts/ci/prek/check_shared_distributions_usage.py +++ b/scripts/ci/prek/check_shared_distributions_usage.py @@ -348,7 +348,7 @@ def get_all_shared_modules(shared_dir: Path) -> list[str]: Get all shared module names from the shared/ directory. Returns list of package names like 'apache-airflow-shared-configuration'. """ - shared_modules = [] + shared_modules: list[str] = [] if not shared_dir.exists(): return shared_modules @@ -495,7 +495,7 @@ def ensure_shared_in_workspace_and_dev(main_pyproject_path: Path, shared_dir: Pa Also ensures they are sorted alphabetically. Returns list of errors if any. """ - errors = [] + errors: list[str] = [] shared_modules = get_all_shared_modules(shared_dir) if not shared_modules: diff --git a/scripts/ci/prek/mypy_folder.py b/scripts/ci/prek/mypy_folder.py index f581901e36578..16606b1db2760 100755 --- a/scripts/ci/prek/mypy_folder.py +++ b/scripts/ci/prek/mypy_folder.py @@ -47,6 +47,7 @@ "airflow-core", *[f"providers/{provider_id.replace('.', '/')}" for provider_id in get_all_provider_ids()], "dev", + "scripts", "devel-common", "task-sdk", "airflow-ctl", diff --git a/scripts/ci/prek/upgrade_important_versions.py b/scripts/ci/prek/upgrade_important_versions.py index 8ecb5af1b7ee5..0e803ffe06c9b 100755 --- a/scripts/ci/prek/upgrade_important_versions.py +++ b/scripts/ci/prek/upgrade_important_versions.py @@ -209,7 +209,7 @@ def get_latest_image_version(image: str) -> str: # DockerHub API endpoint for tags url = f"https://registry.hub.docker.com/v2/repositories/{namespace}/{repository}/tags" - params = {"page_size": 100, "ordering": "last_updated"} + params: dict[str, int | str] = {"page_size": 100, "ordering": "last_updated"} headers = {"User-Agent": "Python requests"} response = requests.get(url, headers=headers, params=params) @@ -480,7 +480,7 @@ def apply_pattern_replacements( # Configuration for packages that follow simple version constant patterns -SIMPLE_VERSION_PATTERNS = { +SIMPLE_VERSION_PATTERNS: dict[str, list[tuple[str, str]]] = { "hatch": [ (r"(HATCH_VERSION = )(\"[0-9.abrc]+\")", 'HATCH_VERSION = "{version}"'), (r"(HATCH_VERSION=)(\"[0-9.abrc]+\")", 'HATCH_VERSION="{version}"'), @@ -609,13 +609,16 @@ def update_file_with_versions( new_content, latest_python_version, AIRFLOW_IMAGE_PYTHON_PATTERNS, keep_length ) + return _apply_simple_regexp_replacements(new_content, versions) + + +def _apply_simple_regexp_replacements(new_content: str, versions: dict[str, str]) -> str: # Apply simple regex replacements for package_name, patterns in SIMPLE_VERSION_PATTERNS.items(): should_upgrade = globals().get(f"UPGRADE_{package_name.upper()}", False) version = versions.get(package_name, "") if should_upgrade and version: new_content = apply_simple_regex_replacements(new_content, version, patterns) - return new_content