Skip to content

re match.group should support __index__ #71364

Closed

Description

@jdemeyer
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']

    Activity

    1. jdemeyer commented on Jun 1, 2016

      @jdemeyer
      ContributorAuthor
      >>> 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
      
    2. serhiy-storchaka commented on Jun 1, 2016

      @serhiy-storchaka
      Member

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

    3. jdemeyer commented on Jun 2, 2016

      @jdemeyer
      ContributorAuthor

      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.

    4. mrabarnett commented on Jun 2, 2016

      mrabarnettmannequin
      Mannequin

      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.

    5. zhangyangyu commented on Jun 15, 2016

      @zhangyangyu
      Member

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

    6. serhiy-storchaka commented on Jun 18, 2016

      @serhiy-storchaka
      Member

      What is the use case?

    7. jdemeyer commented on Jun 18, 2016

      @jdemeyer
      ContributorAuthor

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

    8. serhiy-storchaka commented on Jun 18, 2016

      @serhiy-storchaka
      Member

      Interesting. This is very unusual but reasonable use case.

    9. python-dev commented on Jun 18, 2016

      python-devmannequin
      Mannequin

      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

    10. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions