]> granicus.if.org Git - python/commitdiff
allow longs as indexes to group() (closes #22530)
authorBenjamin Peterson <benjamin@python.org>
Wed, 1 Oct 2014 02:04:28 +0000 (22:04 -0400)
committerBenjamin Peterson <benjamin@python.org>
Wed, 1 Oct 2014 02:04:28 +0000 (22:04 -0400)
Lib/test/test_re.py
Misc/NEWS
Modules/_sre.c

index 7bdf3534ae2733ff3c1ed441bd0ffb59ef431b81..3c77948632ef1a725d9f63793c2907c00ce09e66 100644 (file)
@@ -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
index 07e8855882be1bb0c22e45258ac0718710a84da3..2681b9efaf1a37590bd7fabeff6bd65ab2b078b8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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.
 
index d88c13f3fe6e10e2129f42763d9410b01e102bbc..ec98182b235dfac1ef3d84fb32e56b5a307f2ffb 100644 (file)
@@ -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;