Issue 27177: re match.group should support index (original) (raw)

This issue has been migrated to GitHub: https://github.com/python/cpython/issues/71364

classification

Title: re match.group should support __index__
Type: enhancement Stage: resolved
Components: Regular Expressions Versions: Python 3.6

process

Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: ezio.melotti, jdemeyer, mrabarnett, python-dev, serhiy.storchaka, xiang.zhang
Priority: normal Keywords: patch

Created on 2016-06-01 14:20 by jdemeyer, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
re_match_index.patch jdemeyer,2016-06-01 14:20 Patch for Python 2.7
issue27177.patch xiang.zhang,2016-06-15 07:02 review
Messages (9)
msg266817 - (view) Author: Jeroen Demeyer (jdemeyer) * (Python triager) Date: 2016-06-01 14:20
``` >>> 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 "", line 1, in IndexError: no such group ```
msg266822 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-01 16:35
This looks as new feature and can go only in 3.6.
msg266884 - (view) Author: Jeroen Demeyer (jdemeyer) * (Python triager) Date: 2016-06-02 12:35
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.
msg266885 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2016-06-02 14:00
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.
msg268606 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-06-15 07:02
Attach a patch to add this feature to Py3.6.
msg268775 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-18 07:37
What is the use case?
msg268797 - (view) Author: Jeroen Demeyer (jdemeyer) * (Python triager) Date: 2016-06-18 11:40
My use case is SageMath: http://trac.sagemath.org/ticket/20750
msg268800 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-18 13:06
Interesting. This is very unusual but reasonable use case.
msg268804 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-06-18 13:48
New changeset 0303ab246152 by Serhiy Storchaka in branch 'default': Issue #27177: Match objects in the re module now support index-like objects https://hg.python.org/cpython/rev/0303ab246152
History
Date User Action Args
2022-04-11 14:58:31 admin set github: 71364
2016-06-18 14:13:40 serhiy.storchaka set status: open -> closedresolution: fixedstage: needs patch -> resolved
2016-06-18 13:48:29 python-dev set nosy: + python-devmessages: +
2016-06-18 13:06:55 serhiy.storchaka set assignee: serhiy.storchakamessages: +
2016-06-18 11:40:28 jdemeyer set messages: +
2016-06-18 07:37:37 serhiy.storchaka set messages: +
2016-06-15 07:02:13 xiang.zhang set files: + issue27177.patchnosy: + xiang.zhangmessages: +
2016-06-02 14:00:55 mrabarnett set messages: +
2016-06-02 12:35:59 jdemeyer set messages: +
2016-06-01 16:35:13 serhiy.storchaka set versions: + Python 3.6, - Python 2.7nosy: + serhiy.storchakamessages: + type: enhancementstage: needs patch
2016-06-01 14:20:08 jdemeyer create