]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46289: Make conversion of FormattedValue not optional on ASDL (GH-30467)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 7 Jan 2022 22:30:18 +0000 (14:30 -0800)
committerGitHub <noreply@github.com>
Fri, 7 Jan 2022 22:30:18 +0000 (14:30 -0800)
Automerge-Triggered-By: GH:isidentical
(cherry picked from commit d382f7ee0b98e4ab6ade9384268f25c06be462ad)

Co-authored-by: Batuhan Taskaya <batuhan@python.org>
Misc/NEWS.d/next/Core and Builtins/2022-01-07-23-32-03.bpo-46289.NnjpVc.rst [new file with mode: 0644]
Parser/Python.asdl
Python/Python-ast.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-01-07-23-32-03.bpo-46289.NnjpVc.rst b/Misc/NEWS.d/next/Core and Builtins/2022-01-07-23-32-03.bpo-46289.NnjpVc.rst
new file mode 100644 (file)
index 0000000..816ff58
--- /dev/null
@@ -0,0 +1,2 @@
+ASDL declaration of ``FormattedValue`` has changed to reflect ``conversion``
+field is not optional.
index 85225fc88c5a54ceec5e7aaf892d18063147f5ce..32fdc01a7e0e6ea7b1a4628f82e1e6a55c1b401e 100644 (file)
@@ -74,7 +74,7 @@ module Python
          -- x < 4 < 3 and (x < 4) < 3
          | Compare(expr left, cmpop* ops, expr* comparators)
          | Call(expr func, expr* args, keyword* keywords)
-         | FormattedValue(expr value, int? conversion, expr? format_spec)
+         | FormattedValue(expr value, int conversion, expr? format_spec)
          | JoinedStr(expr* values)
          | Constant(constant value, string? kind)
 
index ce6e6a93ea70f073e3ae1a8b5b6435330a19fd4f..2f84cad7749dd885990c91e537c587a338106d66 100644 (file)
@@ -1312,7 +1312,7 @@ init_types(struct ast_state *state)
         "     | YieldFrom(expr value)\n"
         "     | Compare(expr left, cmpop* ops, expr* comparators)\n"
         "     | Call(expr func, expr* args, keyword* keywords)\n"
-        "     | FormattedValue(expr value, int? conversion, expr? format_spec)\n"
+        "     | FormattedValue(expr value, int conversion, expr? format_spec)\n"
         "     | JoinedStr(expr* values)\n"
         "     | Constant(constant value, string? kind)\n"
         "     | Attribute(expr value, identifier attr, expr_context ctx)\n"
@@ -1402,11 +1402,8 @@ init_types(struct ast_state *state)
     state->FormattedValue_type = make_type(state, "FormattedValue",
                                            state->expr_type,
                                            FormattedValue_fields, 3,
-        "FormattedValue(expr value, int? conversion, expr? format_spec)");
+        "FormattedValue(expr value, int conversion, expr? format_spec)");
     if (!state->FormattedValue_type) return 0;
-    if (PyObject_SetAttr(state->FormattedValue_type, state->conversion,
-        Py_None) == -1)
-        return 0;
     if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
         Py_None) == -1)
         return 0;
@@ -9023,9 +9020,9 @@ obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out, PyArena*
         if (_PyObject_LookupAttr(obj, state->conversion, &tmp) < 0) {
             return 1;
         }
-        if (tmp == NULL || tmp == Py_None) {
-            Py_CLEAR(tmp);
-            conversion = 0;
+        if (tmp == NULL) {
+            PyErr_SetString(PyExc_TypeError, "required field \"conversion\" missing from FormattedValue");
+            return 1;
         }
         else {
             int res;