From 0ac59f93c0e3f91fd994d7245578cce65654fb22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batuhan=20Ta=C5=9Fkaya?= <47358913+isidentical@users.noreply.github.com> Date: Thu, 19 Mar 2020 14:32:28 +0300 Subject: bpo-40000: Improve error messages when validating invalid ast.Constant nodes (GH-19055) Co-authored-by: Pablo Galindo --- Python/ast.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'Python/ast.c') diff --git a/Python/ast.c b/Python/ast.c index 2e9a8d05f7..2b74ed4dbd 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; -- cgit v1.2.1