From 772d809a63f40fd35679da3fb115cdf7fa81bd20 Mon Sep 17 00:00:00 2001 From: Martijn Pieters Date: Tue, 22 Aug 2017 21:16:23 +0100 Subject: bpo-31161: only check for parens error for SyntaxError (#3082) Subclasses such as IndentError and TabError should not have this message applied. --- Objects/exceptions.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'Objects/exceptions.c') diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 190ad06540..13c1be90d8 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -1352,11 +1352,16 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds) Py_DECREF(info); - /* Issue #21669: Custom error for 'print' & 'exec' as statements */ - if (self->text && PyUnicode_Check(self->text)) { - if (_report_missing_parentheses(self) < 0) { - return -1; - } + /* + * Issue #21669: Custom error for 'print' & 'exec' as statements + * + * Only applies to SyntaxError instances, not to subclasses such + * as TabError or IndentationError (see issue #31161) + */ + if ((PyObject*)Py_TYPE(self) == PyExc_SyntaxError && + self->text && PyUnicode_Check(self->text) && + _report_missing_parentheses(self) < 0) { + return -1; } } return 0; -- cgit v1.2.1