Skip to content

Commit b3fe8ee

Browse files
committed
emit FutureWarning for negative start/end indices
1 parent 9eeb4b4 commit b3fe8ee

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

Modules/_sre/sre.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,22 @@ state_init(SRE_STATE* state, PatternObject* pattern, PyObject* string,
453453
}
454454

455455
/* adjust boundaries */
456-
if (start < 0)
456+
if (start < 0) {
457+
PyErr_WarnEx(PyExc_FutureWarning,
458+
"Negative start index will not be truncated to zero in the future",
459+
1);
457460
start = 0;
461+
}
458462
else if (start > length)
459463
start = length;
460464

461-
if (end < 0)
465+
466+
if (end < 0) {
467+
PyErr_WarnEx(PyExc_FutureWarning,
468+
"Negative end index will not be truncated to zero in the future",
469+
1);
462470
end = 0;
471+
}
463472
else if (end > length)
464473
end = length;
465474

0 commit comments

Comments
 (0)