Copilot commented on code in PR #64994:
URL: https://github.com/apache/airflow/pull/64994#discussion_r3066480947
##########
scripts/ci/prek/common_prek_utils.py:
##########
@@ -118,19 +119,29 @@ def read_airflow_version() -> str:
)
+def _read_global_constants_assignment(name: str) -> Any:
+ """Read a top-level assignment from global_constants.py."""
+ tree = ast.parse(GLOBAL_CONSTANTS_PATH.read_text())
+ for node in tree.body:
+ if isinstance(node, ast.Assign):
+ for target in node.targets:
+ if isinstance(target, ast.Name) and target.id == name:
+ return ast.literal_eval(node.value)
+ raise RuntimeError(f"{name} not found in global_constants.py")
+
+
def read_allowed_kubernetes_versions() -> list[str]:
"""Parse ALLOWED_KUBERNETES_VERSIONS from global_constants.py (single
source of truth).
Returns versions without the ``v`` prefix, e.g. ``["1.30.13", "1.31.12",
...]``.
"""
- tree = ast.parse(GLOBAL_CONSTANTS_PATH.read_text())
- for node in tree.body:
- if isinstance(node, ast.Assign):
- for target in node.targets:
- if isinstance(target, ast.Name) and target.id ==
"ALLOWED_KUBERNETES_VERSIONS":
- versions: list[str] = ast.literal_eval(node.value)
- return [v.lstrip("v") for v in versions]
- raise RuntimeError("ALLOWED_KUBERNETES_VERSIONS not found in
global_constants.py")
+ versions: list[str] =
_read_global_constants_assignment("ALLOWED_KUBERNETES_VERSIONS")
+ return [v.lstrip("v") for v in versions]
+
+
+def read_default_python_major_minor_version_for_images() -> str:
+ """Parse DEFAULT_PYTHON_MAJOR_MINOR_VERSION_FOR_IMAGES from
global_constants.py."""
+ return
_read_global_constants_assignment("DEFAULT_PYTHON_MAJOR_MINOR_VERSION_FOR_IMAGES")
Review Comment:
`read_default_python_major_minor_version_for_images()` is annotated to
return `str`, but it returns the `Any` result of
`_read_global_constants_assignment(...)` without validating/casting. Consider
validating the parsed value is a string (and raising a clear error otherwise)
to make failures more obvious if `global_constants.py` changes.
```suggestion
value =
_read_global_constants_assignment("DEFAULT_PYTHON_MAJOR_MINOR_VERSION_FOR_IMAGES")
if not isinstance(value, str):
raise RuntimeError(
"DEFAULT_PYTHON_MAJOR_MINOR_VERSION_FOR_IMAGES in
global_constants.py "
f"must be a string, got {type(value).__name__}"
)
return value
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]