Skip to content

Commit 47bb774

Browse files
committed
Do index conversion for Match.group argument
1 parent d1af6f2 commit 47bb774

File tree

2 files changed

+6
-3
lines changed
  • graalpython

2 files changed

+6
-3
lines changed

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_re.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
*graalpython.lib-python.3.test.test_re.ReTests.test_enum
4646
*graalpython.lib-python.3.test.test_re.ReTests.test_error
4747
*graalpython.lib-python.3.test.test_re.ReTests.test_flags
48+
*graalpython.lib-python.3.test.test_re.ReTests.test_group
4849
*graalpython.lib-python.3.test.test_re.ReTests.test_group_name_in_exception
4950
*graalpython.lib-python.3.test.test_re.ReTests.test_groupdict
5051
*graalpython.lib-python.3.test.test_re.ReTests.test_ignore_case

graalpython/lib-graalpython/_sre.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,12 @@ def __getitem__(self, item):
191191

192192
def __groupidx(self, idx):
193193
try:
194-
if isinstance(idx, str):
194+
if hasattr(idx, '__index__'):
195+
int_idx = int(idx)
196+
if 0 <= int_idx < self.__compiled_regex.groupCount:
197+
return int_idx
198+
else:
195199
return self.__compiled_regex.groups[idx]
196-
elif 0 <= idx < self.__compiled_regex.groupCount:
197-
return idx
198200
except Exception:
199201
pass
200202
raise IndexError("no such group")

0 commit comments

Comments
 (0)