diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-01-07 22:30:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-07 22:30:18 (GMT) |
commit | bea3f42bb7c360921f864949ef7472a7ecb02cd3 (patch) | |
tree | 55d063bef364231ad54a4746cb35e7cde45edca6 /Python | |
parent | e35430bec528dfb1a653cd457ea58b5a08543632 (diff) | |
download | cpython-bea3f42bb7c360921f864949ef7472a7ecb02cd3.zip cpython-bea3f42bb7c360921f864949ef7472a7ecb02cd3.tar.gz cpython-bea3f42bb7c360921f864949ef7472a7ecb02cd3.tar.bz2 |
bpo-46289: Make conversion of FormattedValue not optional on ASDL (GH-30467)
Automerge-Triggered-By: GH:isidentical
(cherry picked from commit d382f7ee0b98e4ab6ade9384268f25c06be462ad)
Co-authored-by: Batuhan Taskaya <batuhan@python.org>
Diffstat (limited to 'Python')
-rw-r--r-- | Python/Python-ast.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c index ce6e6a9..2f84cad 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -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; |