Commit bc4ece57 authored by Benjamin Peterson's avatar Benjamin Peterson

allow longs as indexes to group() (closes #22530)

parent bc4a834b
......@@ -971,6 +971,10 @@ subpattern None
pat.split(string='abracadabra', maxsplit=1),
['', 'ab', 'racadabra'])
def test_match_group_takes_long(self):
self.assertEqual(re.match("(foo)", "foo").group(1L), "foo")
self.assertRaises(IndexError, re.match("", "").group, sys.maxint + 1)
def run_re_tests():
from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR
......
......@@ -31,6 +31,9 @@ Core and Builtins
Library
-------
- Issue #22530: Allow the ``group()`` method of regular expression match objects
to take a ``long`` as an index.
- Issue #22517: When a io.BufferedRWPair object is deallocated, clear its
weakrefs.
......
......@@ -3301,7 +3301,7 @@ match_getindex(MatchObject* self, PyObject* index)
{
Py_ssize_t i;
if (PyInt_Check(index))
if (PyInt_Check(index) || PyLong_Check(index))
return PyInt_AsSsize_t(index);
i = -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment