You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/serhiy-storchaka'closed_at=<Date2016-06-18.14:13:40.038>created_at=<Date2016-06-01.14:20:08.737>labels= ['expert-regex', 'type-feature']
title='re match.group should support __index__'updated_at=<Date2016-06-18.14:13:40.037>user='https://github.com/jdemeyer'
>>> class zero(object):
... def __index__(self):
... return 0
...
>>> z = zero()
>>> import re
>>> p = re.compile('(a)b')
>>> m = p.match('ab')
>>> m.group(0)
'ab'
>>> m.group(z)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: no such group
I would still argue that it's a bug. The intention of PEP-357 is that __index__ should be used whenever some object needs to be converted to a Py_ssize_t, which is exactly what you do here.
mrabarnett commented on Jun 2, 2016
mrabarnettmannequin
Mannequin
More actions
It would be a bug if it was supported but gave the wrong result.
It has never been supported (the re module predates PEP-357), so it's a new feature.
Activity
jdemeyer commentedon Jun 1, 2016
serhiy-storchaka commentedon Jun 1, 2016
This looks as new feature and can go only in 3.6.
jdemeyer commentedon Jun 2, 2016
I would still argue that it's a bug. The intention of PEP-357 is that __index__ should be used whenever some object needs to be converted to a Py_ssize_t, which is exactly what you do here.
mrabarnett commentedon Jun 2, 2016
It would be a bug if it was supported but gave the wrong result.
It has never been supported (the re module predates PEP-357), so it's a new feature.
zhangyangyu commentedon Jun 15, 2016
Attach a patch to add this feature to Py3.6.
serhiy-storchaka commentedon Jun 18, 2016
What is the use case?
jdemeyer commentedon Jun 18, 2016
My use case is SageMath: http://trac.sagemath.org/ticket/20750
serhiy-storchaka commentedon Jun 18, 2016
Interesting. This is very unusual but reasonable use case.
python-dev commentedon Jun 18, 2016
New changeset 0303ab246152 by Serhiy Storchaka in branch 'default':
Issue bpo-27177: Match objects in the re module now support index-like objects
https://hg.python.org/cpython/rev/0303ab246152