classification
Title: re rejects index of type long on 2.7
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gregory.p.smith, gvanrossum, python-dev, refi64, steven.daprano
Priority: normal Keywords: patch

Created on 2014-10-01 00:39 by refi64, last changed 2014-10-02 21:22 by gregory.p.smith. This issue is now closed.

Files
File name Uploaded Description Edit
re.patch refi64, 2014-10-01 00:39 review
Messages (5)
msg228043 - (view) Author: Ryan Gonzalez (refi64) * Date: 2014-10-01 00:39
This should work (but doesn't):

Python 2.7.8+ (2.7:63dc1e32b715, Sep 30 2014, 19:24:46) 
[GCC 4.2.1 Compatible Clang 3.5.0 (207381)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> re.match('(foo)', 'foo').group(1L)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: no such group
>>> 

I *think* the attached patch fixes it (but I'm not quite sure).

Here's the relevant mailing list thread: https://mail.python.org/pipermail/python-ideas/2014-September/029590.html.
msg228049 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2014-10-01 01:03
As I explained on the thread (possibly my post crossed in the mail with Ryan's patch) I don't believe this is a bug fix. MatchObject.group has only accepted actual ints, not longs, since Python 1.5 (tested 1.5, 2.4-2.7). Nor is there any requirement to support longs, since the number of groups cannot exceed that represented by a regular int.

I don't believe this is a bug fix, I believe this is a new feature, and as such inappropriate for 2.7.
msg228053 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2014-10-01 01:46
I haven't seen the fix, but any place where an int is accepted but a long is not, is a bug. The language has been on a long trip to making the two types interchangeable and this seems one of the last remnants.
msg228054 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-10-01 02:04
New changeset 30f72ed73c3b by Benjamin Peterson in branch '2.7':
allow longs as indexes to group() (closes #22530)
https://hg.python.org/cpython/rev/30f72ed73c3b
msg228260 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2014-10-02 21:22
thanks.  btw an alternative type check to consider in these situations: PyIndex_Check

https://docs.python.org/2/c-api/number.html#c.PyIndex_Check

but what you wrote works.
History
Date User Action Args
2014-10-02 21:22:34gregory.p.smithsetnosy: + gregory.p.smith
messages: + msg228260
2014-10-01 02:04:37python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg228054

resolution: not a bug -> fixed
stage: resolved
2014-10-01 01:46:22gvanrossumsetnosy: + gvanrossum
messages: + msg228053
2014-10-01 01:03:01steven.dapranosetresolution: not a bug

messages: + msg228049
nosy: + steven.daprano
2014-10-01 00:39:53refi64create