mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Merge 8d661b6807
into 61dd9fdad7
This commit is contained in:
commit
115bc399ec
4 changed files with 29 additions and 2 deletions
|
@ -1044,6 +1044,8 @@ Functions
|
|||
.. versionchanged:: 3.7
|
||||
Non-empty matches can now start just after a previous empty match.
|
||||
|
||||
.. versionchanged:: 3.13
|
||||
Negative start and end indices will no longer be truncated to zero in Python 3.15.
|
||||
|
||||
.. function:: finditer(pattern, string, flags=0)
|
||||
|
||||
|
@ -1059,6 +1061,8 @@ Functions
|
|||
.. versionchanged:: 3.7
|
||||
Non-empty matches can now start just after a previous empty match.
|
||||
|
||||
.. versionchanged:: 3.13
|
||||
Negative start and end indices will no longer be truncated to zero in Python 3.15.
|
||||
|
||||
.. function:: sub(pattern, repl, string, count=0, flags=0)
|
||||
|
||||
|
|
|
@ -503,6 +503,18 @@ class ReTests(unittest.TestCase):
|
|||
self.assertEqual(re.findall(r"(a|(b))", "aba"),
|
||||
[("a", ""),("b", "b"),("a", "")])
|
||||
|
||||
def test_bug_7940_raises_future_warnings(self):
|
||||
"""Test to ensure the FutureWarnings are raised."""
|
||||
pat = re.compile(".")
|
||||
with self.assertWarns(FutureWarning) as cm:
|
||||
pat.findall("abcd", -1, 1)
|
||||
self.assertEqual(str(cm.warning), "Negative start index will not "
|
||||
"be truncated to zero in Python 3.15")
|
||||
with self.assertWarns(FutureWarning) as cm:
|
||||
pat.findall("abcd", 1, -1)
|
||||
self.assertEqual(str(cm.warning), "Negative end index will not "
|
||||
"be truncated to zero in Python 3.15")
|
||||
|
||||
def test_re_match(self):
|
||||
for string in 'a', S('a'):
|
||||
self.assertEqual(re.match('a', string).groups(), ())
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Emit a FutureWarning when truncating negative start and end indices in re.finditer
|
||||
and re.findall.
|
|
@ -572,13 +572,22 @@ state_init(SRE_STATE* state, PatternObject* pattern, PyObject* string,
|
|||
}
|
||||
|
||||
/* adjust boundaries */
|
||||
if (start < 0)
|
||||
if (start < 0) {
|
||||
PyErr_WarnEx(PyExc_FutureWarning,
|
||||
"Negative start index will not be truncated to zero in Python 3.15",
|
||||
1);
|
||||
start = 0;
|
||||
}
|
||||
else if (start > length)
|
||||
start = length;
|
||||
|
||||
if (end < 0)
|
||||
|
||||
if (end < 0) {
|
||||
PyErr_WarnEx(PyExc_FutureWarning,
|
||||
"Negative end index will not be truncated to zero in Python 3.15",
|
||||
1);
|
||||
end = 0;
|
||||
}
|
||||
else if (end > length)
|
||||
end = length;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue