summaryrefslogtreecommitdiffstats
path: root/Python/Python-ast.c
diff options
context:
space:
mode:
authorBatuhan Taskaya <batuhan@python.org>2022-01-07 21:05:28 (GMT)
committerGitHub <noreply@github.com>2022-01-07 21:05:28 (GMT)
commitd382f7ee0b98e4ab6ade9384268f25c06be462ad (patch)
tree17e46a04ab58a02dfc560d560ec7966f78d4a493 /Python/Python-ast.c
parent6d07a9fb7cb31433c376a1aa20ea32001da0a418 (diff)
downloadcpython-d382f7ee0b98e4ab6ade9384268f25c06be462ad.zip
cpython-d382f7ee0b98e4ab6ade9384268f25c06be462ad.tar.gz
cpython-d382f7ee0b98e4ab6ade9384268f25c06be462ad.tar.bz2
bpo-46289: Make conversion of FormattedValue not optional on ASDL (GH-30467)
Automerge-Triggered-By: GH:isidentical
Diffstat (limited to 'Python/Python-ast.c')
-rw-r--r--Python/Python-ast.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 1670184..da79463 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -1324,7 +1324,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"
@@ -1414,11 +1414,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;
@@ -9249,9 +9246,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;