Skip to content

Commit 00c3c14

Browse files
committed
Fix total regex group count
1 parent e629654 commit 00c3c14

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

graalpython/lib-graalpython/_sre.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,22 @@ def _is_bytes_like(object):
244244
class SRE_Pattern():
245245
def __init__(self, pattern, flags):
246246
self.__binary = isinstance(pattern, bytes)
247-
self.groups = 0
248247
self.pattern = pattern
249248
self.flags = flags
250249
flags_str = []
251250
for char,flag in FLAGS.items():
252251
if flags & flag:
253252
flags_str.append(char)
254253
self.flags_str = "".join(flags_str)
255-
self.__compiled_regexes = dict()
256-
groupindex = dict()
257-
if self.__tregex_compile(self.pattern).groups is not None:
258-
for group_name in dir(self.__tregex_compile(self.pattern).groups):
259-
groups = self.__tregex_compile(self.pattern).groups
260-
self.groups = len(dir(groups))
261-
groupindex[group_name] = groups[group_name]
262-
self.groupindex = _mappingproxy(groupindex)
254+
self.__compiled_regexes = {}
255+
compiled_regex = self.__tregex_compile(self.pattern)
256+
self.groups = compiled_regex.groupCount - 1
257+
groups = compiled_regex.groups
258+
if groups is None:
259+
self.groupindex = {}
260+
else:
261+
group_names = dir(groups)
262+
self.groupindex = _mappingproxy({name: groups[name] for name in group_names})
263263

264264
def __check_input_type(self, input):
265265
if not isinstance(input, str) and not _is_bytes_like(input):

0 commit comments

Comments
 (0)