Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re match.group should support __index__ #71364

Closed
jdemeyer opened this issue Jun 1, 2016 · 9 comments
Closed

re match.group should support __index__ #71364

jdemeyer opened this issue Jun 1, 2016 · 9 comments
Assignees
Labels
topic-regex type-feature A feature request or enhancement

Comments

@jdemeyer
Copy link
Contributor

jdemeyer commented Jun 1, 2016

BPO 27177
Nosy @ezio-melotti, @serhiy-storchaka, @jdemeyer, @zhangyangyu
Files
  • re_match_index.patch: Patch for Python 2.7
  • issue27177.patch
  • 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 = <Date 2016-06-18.14:13:40.038>
    created_at = <Date 2016-06-01.14:20:08.737>
    labels = ['expert-regex', 'type-feature']
    title = 're match.group should support __index__'
    updated_at = <Date 2016-06-18.14:13:40.037>
    user = 'https://github.com/jdemeyer'

    bugs.python.org fields:

    activity = <Date 2016-06-18.14:13:40.037>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2016-06-18.14:13:40.038>
    closer = 'serhiy.storchaka'
    components = ['Regular Expressions']
    creation = <Date 2016-06-01.14:20:08.737>
    creator = 'jdemeyer'
    dependencies = []
    files = ['43084', '43396']
    hgrepos = []
    issue_num = 27177
    keywords = ['patch']
    message_count = 9.0
    messages = ['266817', '266822', '266884', '266885', '268606', '268775', '268797', '268800', '268804']
    nosy_count = 6.0
    nosy_names = ['ezio.melotti', 'mrabarnett', 'python-dev', 'serhiy.storchaka', 'jdemeyer', 'xiang.zhang']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue27177'
    versions = ['Python 3.6']

    @jdemeyer
    Copy link
    Contributor Author

    jdemeyer commented Jun 1, 2016

    >>> 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
    

    @serhiy-storchaka
    Copy link
    Member

    This looks as new feature and can go only in 3.6.

    @serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label Jun 1, 2016
    @jdemeyer
    Copy link
    Contributor Author

    jdemeyer commented 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
    Copy link
    Mannequin

    mrabarnett mannequin commented 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
    Copy link
    Member

    Attach a patch to add this feature to Py3.6.

    @serhiy-storchaka
    Copy link
    Member

    What is the use case?

    @jdemeyer
    Copy link
    Contributor Author

    My use case is SageMath: http://trac.sagemath.org/ticket/20750

    @serhiy-storchaka
    Copy link
    Member

    Interesting. This is very unusual but reasonable use case.

    @serhiy-storchaka serhiy-storchaka self-assigned this Jun 18, 2016
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented 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

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-regex type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants