Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: py3.6 Changeset: r93459:5e9a2c6daf17 Date: 2017-12-17 19:19 +0100 http://bitbucket.org/pypy/pypy/changeset/5e9a2c6daf17/
Log: re.Match.group() now accepts index-like objects. diff --git a/pypy/module/_sre/interp_sre.py b/pypy/module/_sre/interp_sre.py --- a/pypy/module/_sre/interp_sre.py +++ b/pypy/module/_sre/interp_sre.py @@ -604,7 +604,7 @@ def do_span(self, w_arg): space = self.space try: - groupnum = space.int_w(w_arg) + groupnum = space.getindex_w(w_arg, space.w_OverflowError) except OperationError as e: if not e.match(space, space.w_TypeError) and \ not e.match(space, space.w_OverflowError): diff --git a/pypy/module/_sre/test/test_app_sre.py b/pypy/module/_sre/test/test_app_sre.py --- a/pypy/module/_sre/test/test_app_sre.py +++ b/pypy/module/_sre/test/test_app_sre.py @@ -227,6 +227,15 @@ exc = raises(IndexError, re.match("", "").group, sys.maxsize + 1) assert str(exc.value) == "no such group" + def test_group_takes_index(self): + import re + class Index: + def __init__(self, value): + self.value = value + def __index__(self): + return self.value + assert re.match("(foo)", "foo").group(Index(1)) == "foo" + def test_expand(self): import re m = re.search("a(..)(?P<name>..)", "ab1bc") _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit