[Python-checkins] bpo-46289: Make conversion of FormattedValue not optional on ASDL (GH-30467)
miss-islington
webhook-mailer at python.org
Fri Jan 7 16:05:37 EST 2022
https://github.com/python/cpython/commit/d382f7ee0b98e4ab6ade9384268f25c06be462ad
commit: d382f7ee0b98e4ab6ade9384268f25c06be462ad
branch: main
author: Batuhan Taskaya <batuhan at python.org>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-01-07T13:05:28-08:00
summary:
bpo-46289: Make conversion of FormattedValue not optional on ASDL (GH-30467)
Automerge-Triggered-By: GH:isidentical
files:
A Misc/NEWS.d/next/Core and Builtins/2022-01-07-23-32-03.bpo-46289.NnjpVc.rst
M Parser/Python.asdl
M 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
index 0000000000000..816ff585f14e6
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-01-07-23-32-03.bpo-46289.NnjpVc.rst
@@ -0,0 +1,2 @@
+ASDL declaration of ``FormattedValue`` has changed to reflect ``conversion``
+field is not optional.
diff --git a/Parser/Python.asdl b/Parser/Python.asdl
index 4a61bda701b47..e9423a7c984f2 100644
--- a/Parser/Python.asdl
+++ b/Parser/Python.asdl
@@ -75,7 +75,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)
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 167018482077d..da79463375a1a 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;
More information about the Python-checkins
mailing list