summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorBatuhan Taşkaya <47358913+isidentical@users.noreply.github.com>2020-03-19 11:32:28 (GMT)
committerGitHub <noreply@github.com>2020-03-19 11:32:28 (GMT)
commit0ac59f93c0e3f91fd994d7245578cce65654fb22 (patch)
treec1eab66af2739b9b8aa257b082fac7b732a55983 /Python/ast.c
parent50e6e991781db761c496561a995541ca8d83ff87 (diff)
downloadcpython-0ac59f93c0e3f91fd994d7245578cce65654fb22.zip
cpython-0ac59f93c0e3f91fd994d7245578cce65654fb22.tar.gz
cpython-0ac59f93c0e3f91fd994d7245578cce65654fb22.tar.bz2
bpo-40000: Improve error messages when validating invalid ast.Constant nodes (GH-19055)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Python/ast.c')
-rw-r--r--Python/ast.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/Python/ast.c b/Python/ast.c
index 2e9a8d0..2b74ed4 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -147,6 +147,11 @@ validate_constant(PyObject *value)
return 1;
}
+ if (!PyErr_Occurred()) {
+ PyErr_Format(PyExc_TypeError,
+ "got an invalid type in Constant: %s",
+ _PyType_Name(Py_TYPE(value)));
+ }
return 0;
}
@@ -261,9 +266,6 @@ validate_expr(expr_ty exp, expr_context_ty ctx)
validate_keywords(exp->v.Call.keywords);
case Constant_kind:
if (!validate_constant(exp->v.Constant.value)) {
- PyErr_Format(PyExc_TypeError,
- "got an invalid type in Constant: %s",
- _PyType_Name(Py_TYPE(exp->v.Constant.value)));
return 0;
}
return 1;