bpo-32685: Fixes print suggestion hint in case of multiple statements on the same line by CuriousLearner · Pull Request #5376 · python/cpython

Expand Up @@ -2844,18 +2844,17 @@ _set_legacy_print_statement_msg(PySyntaxErrorObject *self, Py_ssize_t start) if (strip_sep_obj == NULL) return -1;
// PRINT_OFFSET is to remove `print ` word from the data. const int PRINT_OFFSET = 6; // PRINT_OFFSET is to accommodate the removal of `print ` word (6 chars) // and the offset to the `print` call in the statement. const Py_ssize_t PRINT_OFFSET = (Py_ssize_t)(6 + start); const int STRIP_BOTH = 2; // Issue 32028: Handle case when whitespace is used with print call PyObject *initial_data = _PyUnicode_XStrip(self->text, STRIP_BOTH, strip_sep_obj); if (initial_data == NULL) { Py_DECREF(strip_sep_obj); return -1; } Py_ssize_t text_len = PyUnicode_GET_LENGTH(initial_data); PyObject *data = PyUnicode_Substring(initial_data, PRINT_OFFSET, text_len); Py_DECREF(initial_data); Py_ssize_t text_len = PyUnicode_GET_LENGTH(self->text); const int RIGHT_OFFSET = PyUnicode_FindChar(self->text, ';', PRINT_OFFSET, text_len, 1); if (RIGHT_OFFSET != -1) // Normal case when multiple statements are not on the same line separated by `;` text_len = RIGHT_OFFSET; PyObject *data = PyUnicode_Substring(self->text, PRINT_OFFSET, text_len); if (data == NULL) { Py_DECREF(strip_sep_obj); return -1; Expand Down