[3.9] bpo-35975: Only use cf_feature_version if PyCF_ONLY_AST in cf_flags (#21022)

diff --git a/Python/ast.c b/Python/ast.c
index 3278586..c7ba4d9 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -777,7 +777,8 @@
     /* borrowed reference */
     c.c_filename = filename;
     c.c_normalize = NULL;
-    c.c_feature_version = flags ? flags->cf_feature_version : PY_MINOR_VERSION;
+    c.c_feature_version = flags && (flags->cf_flags & PyCF_ONLY_AST) ?
+        flags->cf_feature_version : PY_MINOR_VERSION;
 
     if (TYPE(n) == encoding_decl)
         n = CHILD(n, 0);
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index cb0e3b0..70748dc 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1402,7 +1402,7 @@
     PyCompilerFlags localflags = _PyCompilerFlags_INIT;
     perrdetail err;
     int iflags = PARSER_FLAGS(flags);
-    if (flags && flags->cf_feature_version < 7)
+    if (flags && (flags->cf_flags & PyCF_ONLY_AST) && flags->cf_feature_version < 7)
         iflags |= PyPARSE_ASYNC_HACKS;
 
     node *n = PyParser_ParseStringObject(s, filename,