summaryrefslogtreecommitdiffstats
path: root/Objects/exceptions.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r--Objects/exceptions.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index f286ec0..271e293 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -1356,11 +1356,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;