[Python-checkins] cpython (2.7): allow longs as indexes to group() (closes #22530)
benjamin.peterson
python-checkins at python.org
Wed Oct 1 04:04:42 CEST 2014
https://hg.python.org/cpython/rev/30f72ed73c3b
changeset: 92708:30f72ed73c3b
branch: 2.7
parent: 92705:92b5ae0a229f
user: Benjamin Peterson <benjamin at python.org>
date: Tue Sep 30 22:04:28 2014 -0400
summary:
allow longs as indexes to group() (closes #22530)
files:
Lib/test/test_re.py | 4 ++++
Misc/NEWS | 3 +++
Modules/_sre.c | 2 +-
3 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -971,6 +971,10 @@
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
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -31,6 +31,9 @@
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.
diff --git a/Modules/_sre.c b/Modules/_sre.c
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -3301,7 +3301,7 @@
{
Py_ssize_t i;
- if (PyInt_Check(index))
+ if (PyInt_Check(index) || PyLong_Check(index))
return PyInt_AsSsize_t(index);
i = -1;
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list