Skip to content

re: convert re flags to (much friendlier) IntFlag constants #72269

Closed

Description

@ethanfurman
BPO 28082
Nosy @gvanrossum, @rhettinger, @vstinner, @ethanfurman, @serhiy-storchaka
Files
  • issue-re.stoneleaf.02.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/ethanfurman'
    closed_at = <Date 2016-11-21.16:31:14.567>
    created_at = <Date 2016-09-11.20:29:30.011>
    labels = ['type-feature']
    title = 're: convert re flags to (much friendlier) IntFlag constants'
    updated_at = <Date 2016-11-21.16:40:28.001>
    user = 'https://github.com/ethanfurman'

    bugs.python.org fields:

    activity = <Date 2016-11-21.16:40:28.001>
    actor = 'python-dev'
    assignee = 'ethan.furman'
    closed = True
    closed_date = <Date 2016-11-21.16:31:14.567>
    closer = 'python-dev'
    components = []
    creation = <Date 2016-09-11.20:29:30.011>
    creator = 'ethan.furman'
    dependencies = []
    files = ['44566']
    hgrepos = []
    issue_num = 28082
    keywords = ['patch']
    message_count = 16.0
    messages = ['275848', '275849', '275860', '275863', '275864', '275865', '275869', '275880', '275881', '275883', '280257', '280263', '280754', '280836', '281377', '281380']
    nosy_count = 6.0
    nosy_names = ['gvanrossum', 'rhettinger', 'vstinner', 'ethan.furman', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue28082'
    versions = ['Python 3.6']

    Activity

    1. ethanfurman commented on Sep 11, 2016

      @ethanfurman
      MemberAuthor

      Split from bpo-23591.

    2. python-dev commented on Sep 11, 2016

      python-devmannequin
      Mannequin

      New changeset 223731925d06 by Ethan Furman in branch 'default':
      bpo-28082: use IntFlag for re constants
      https://hg.python.org/cpython/rev/223731925d06

    3. rhettinger commented on Sep 11, 2016

      @rhettinger
      Contributor

      Guido, is this something you wanted to happen? I thought you had objected to propagating the four flavors of enum throughout the standard library, particularly for long standing, stable APIs.

      AFAICT, no one has ever requested this for the re module, nor is there any demonstrated need. As a heavy user of regexes, I've have never looked at the flag values (and if I had, it wouldn't have been helpful to hide that these are integer values rather than giving them both a new type and an unattractive appearance: <Flag.ASCII|IGNORECASE: 258>. Also, prior to this change, the re module and its sre components had no external dependencies and did not require any other modules to be loaded in memory to run.

      If changes like this do go in, it needs better names (i.e. Flag -> RegexFlag) so that someone using typing doesn't end-up many distinct kinds of integer flags all being called Flag.

    4. python-dev commented on Sep 11, 2016

      python-devmannequin
      Mannequin

      New changeset 7369ec91d0f7 by Ethan Furman in branch 'default':
      bpo-28082: better name for Flag
      https://hg.python.org/cpython/rev/7369ec91d0f7

    5. ethanfurman commented on Sep 11, 2016

      @ethanfurman
      MemberAuthor

      The patch was initially from Serhiy as part of bpo-23591. So it's safe to say at least one person requested it, and a core dev at that.

      I will happily make it two people: as an occasional user of re having the constants be named makes it much easier for me to use; I daresay that is true for other occasional users. IIRC giving names to numbers was one of the motivating factors in having Enum in the first place.

      I do agree that RegexFlag is a better name -- I wasn't real happy with Flag but didn't want to miss the cutoff.

    6. serhiy-storchaka commented on Sep 11, 2016

      @serhiy-storchaka
      Member

      re flags was the primary motive of introducing general IntFlags. This would help to handle frequent user error. Original issue is bpo-11957.

    7. ethanfurman commented on Sep 11, 2016

      @ethanfurman
      MemberAuthor

      Note: still need to update docs.

    8. gvanrossum commented on Sep 11, 2016

      @gvanrossum
      Member

      Yeah, I am generally in favor of this. Just yesterday there was a bug report (bpo-28070) where someone claimed that the flags from r'(ix)A' were incorrect. They were 96 and should be 98. (He was right, and it was fixed already.) The way he had to prove that was rather indirect. If the flags had printed like with this proposal it would have been much more straightforward.

    9. rhettinger commented on Sep 11, 2016

      @rhettinger
      Contributor

      Ethan, can you give this class a better name than "Flags"? Perhaps something like "RegexFlags" or somesuch?

    10. ethanfurman commented on Sep 11, 2016

      @ethanfurman
      MemberAuthor

      I did, immediately after your first post -- it's now RegexFlag. Thank you for the suggestion! Naming things can be hard, especially when trying to beat a deadline.

    11. vstinner commented on Nov 7, 2016

      @vstinner
      Member

      The changeset 223731925d06 caused a performance regression: see issue bpo-28637.

    12. python-dev commented on Nov 7, 2016

      python-devmannequin
      Mannequin

      New changeset d903a243c281 by Victor Stinner in branch '3.6':
      Issue bpo-28637: Revert issue bpo-28082, don't import enum in re
      https://hg.python.org/cpython/rev/d903a243c281

    13. python-dev commented on Nov 14, 2016

      python-devmannequin
      Mannequin

      New changeset 5fd69d4a93e0 by Victor Stinner in branch '3.6':
      Issue bpo-28637: Reapply changeset 223731925d06
      https://hg.python.org/cpython/rev/5fd69d4a93e0

      New changeset be66786e95de by Victor Stinner in branch '3.6':
      Issue bpo-28082: Add basic unit tests on re enums
      https://hg.python.org/cpython/rev/be66786e95de

    14. vstinner commented on Nov 15, 2016

      @vstinner
      Member

      The change 5fd69d4a93e0 (use IntFlag for re constants) made the "regex_compile" benchmark slower:

      Median +- std dev: [71c1970f27b6] 388 ms +- 3 ms -> [3cf248d10bed] 470 ms +- 4 ms: 1.21x slower

    15. python-dev commented on Nov 21, 2016

      python-devmannequin
      Mannequin

      New changeset 176fc21f8430 by Ethan Furman in branch '3.6':
      closes bpo-28082: doc update and NEWS entry
      https://hg.python.org/cpython/rev/176fc21f8430

    16. python-dev commented on Nov 21, 2016

      python-devmannequin
      Mannequin

      New changeset 493359386360 by Ethan Furman in branch '3.6':
      bpo-28082: actually include NEWS entry
      https://hg.python.org/cpython/rev/493359386360

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

    Assignees

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions