This is an automated email from the ASF dual-hosted git repository.
ash 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 3de9e1481d Add in backport of astunparse where needed in static checks
(#42503)
3de9e1481d is described below
commit 3de9e1481d2aa7e737ba98526570d5e339e1eebd
Author: Ash Berlin-Taylor <[email protected]>
AuthorDate: Thu Sep 26 15:48:23 2024 +0100
Add in backport of astunparse where needed in static checks (#42503)
---
hatch_build.py | 1 +
scripts/ci/pre_commit/check_deferrable_default.py | 8 +++++++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/hatch_build.py b/hatch_build.py
index efd3ccd560..e4cd1e6030 100644
--- a/hatch_build.py
+++ b/hatch_build.py
@@ -239,6 +239,7 @@ DEVEL_EXTRAS: dict[str, list[str]] = {
"blinker>=1.7.0",
],
"devel-static-checks": [
+ "astunparse>=1.6.3; python_version < '3.9'",
"black>=23.12.0",
"pre-commit>=3.5.0",
"ruff==0.5.5",
diff --git a/scripts/ci/pre_commit/check_deferrable_default.py
b/scripts/ci/pre_commit/check_deferrable_default.py
index bfde61f231..a007739083 100755
--- a/scripts/ci/pre_commit/check_deferrable_default.py
+++ b/scripts/ci/pre_commit/check_deferrable_default.py
@@ -25,6 +25,12 @@ import os
import sys
from typing import Iterator
+if hasattr(ast, "unparse"):
+ # Py 3.9+
+ unparse = ast.unparse
+else:
+ from astunparse import unparse # type: ignore[no-redef]
+
import libcst as cst
from libcst.codemod import CodemodContext
from libcst.codemod.visitors import AddImportsVisitor
@@ -78,7 +84,7 @@ class DefaultDeferrableTransformer(cst.CSTTransformer):
def _is_valid_deferrable_default(default: ast.AST) -> bool:
"""Check whether default is 'conf.getboolean("operators",
"default_deferrable", fallback=False)'"""
- return ast.unparse(default) == "conf.getboolean('operators',
'default_deferrable', fallback=False)"
+ return unparse(default) == "conf.getboolean('operators',
'default_deferrable', fallback=False)"
def iter_check_deferrable_default_errors(module_filename: str) ->
Iterator[str]: