GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — re.sub confusion between count and flags args · Issue #56166 · python/cpython

re.sub confusion between count and flags args #56166

New issue
Copy link
New issue
Copy link
Closed
Closed
re.sub confusion between count and flags args#56166
Copy link
Assignees
ezio-melotti
Labels
3.7 (EOL)end of lifeend of lifetopic-regextype-featureA feature request or enhancementA feature request or enhancement

Description

mindauga
mannequin
opened on Apr 29, 2011
Issue body actions
BPO 11957
Nosy @rhettinger, @terryjreedy, @vstinner, @ericvsmith, @jwilk, @ezio-melotti, @merwok, @serhiy-storchaka
Dependencies
  • bpo-23591: enum: Add Flags and IntFlags
  • Files
  • patch_11957
  • re_keyword_only.patch
  • re_check_flags_type.patch
  • re_deprecate_positional_count.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/ezio-melotti'
    closed_at = None
    created_at = <Date 2011-04-29.18:27:10.198>
    labels = ['expert-regex', 'type-feature', '3.7']
    title = 're.sub confusion between count and flags args'
    updated_at = <Date 2017-04-14.18:55:29.189>
    user = 'https://bugs.python.org/mindauga'

    bugs.python.org fields:

    activity = <Date 2017-04-14.18:55:29.189>
    actor = 'jwilk'
    assignee = 'ezio.melotti'
    closed = False
    closed_date = None
    closer = None
    components = ['Regular Expressions']
    creation = <Date 2011-04-29.18:27:10.198>
    creator = 'mindauga'
    dependencies = ['23591']
    files = ['30821', '37067', '44825', '44826']
    hgrepos = []
    issue_num = 11957
    keywords = ['patch']
    message_count = 27.0
    messages = ['134806', '134820', '134830', '135371', '135386', '135391', '136657', '143520', '186784', '186825', '186832', '186844', '186856', '192416', '230223', '230224', '230226', '230236', '230237', '230238', '230358', '230375', '277386', '277398', '291655', '291659', '291677']
    nosy_count = 13.0
    nosy_names = ['rhettinger', 'terry.reedy', 'vstinner', 'eric.smith', 'jwilk', 'ezio.melotti', 'eric.araujo', 'mrabarnett', 'python-dev', 'mindauga', 'serhiy.storchaka', 'mmilkin', 'umi']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue11957'
    versions = ['Python 3.6', 'Python 3.7']

    Linked PRs

    • gh-56166: Deprecate passing counts and maxsplit via position in re #107767
    • gh-56166: Deprecate passing confusing positional arguments in re functions #107778
    Reacted by Matúš Ferech

    Activity

    Next
    1. mindauga commented on Apr 29, 2011

      @mindauga
      mindaugamannequin
      on Apr 29, 2011
      MannequinAuthor
      More actions

      re.sub don't substitute not ASCII characters:

      Python 2.7.1 (r271:86832, Apr 15 2011, 12:11:58) Arch Linux

      >>import re

      >>a=u'aaa'
      >>print re.search('(\w+)',a,re.U).groups()
      (u'aaa')
      >>print re.sub('(\w+)','x',a,re.U)
      x

        BUT:
      

      >>a=u'ąąą'
      >>print re.search('(\w+)',a,re.U).groups()
      (u'\u0105\u0105\u0105')
      >>print re.sub('(\w+)','x',a,re.U)
      ąąą

    2. mindauga
      added
      topic-unicode
      topic-regex
      on Apr 29, 2011
    3. ericvsmith commented on Apr 29, 2011

      @ericvsmith
      ericvsmith
      on Apr 29, 2011
      Member
      More actions

      The 4th parameter to re.sub() is a count, not flags.

      Reacted by arsen671games3
    4. ezio-melotti commented on Apr 30, 2011

      @ezio-melotti
      ezio-melotti
      on Apr 30, 2011
      Member
      More actions

      Since this has been reported already several times (see e.g. bpo-11947), and it's a fairly common mistake, I think we should do something to avoid it.

      A few possibilities are:

      1. add a warning in the doc;
      2. make count and flag keyword-only argument (raising a deprecation warning in 3.3 and actually change it later);
      3. change the regex flags to some object that can be distinguished from ints and raise an error when a flag is passed to count;
    5. ezio-melotti
      changed the title [-]re.sub problem with unicode string[/-] [+]re.sub confusion between count and flags args[/+] on Apr 30, 2011
    6. terryjreedy commented on May 6, 2011

      @terryjreedy
      terryjreedy
      on May 6, 2011
      Member
      More actions

      I like the idea of an internal REflag class with __new__, __or__, and __repr__==str. Str(re.A|re.L) might print as
      "REflag: re.ASCII | re.IGNORE"
      If it is *not* an int subclass, any attempt to use or mix with an int would raise. I checked and the doc only promises that flags can be or'ed. An __and__ method might be added if it were thought that people currently use & to check for flags set, though that is not currently promised.

    7. mrabarnett commented on May 6, 2011

      @mrabarnett
      mrabarnettmannequin
      on May 6, 2011
      Mannequin
      More actions

      Something like "<re.Flag ASCII | IGNORE>" may be more Pythonic.

    8. terryjreedy commented on May 7, 2011

      @terryjreedy
      terryjreedy
      on May 7, 2011
      Member
      More actions

      Agreed, if we go that route.

    9. rhettinger
      self-assigned this
      on May 14, 2011
    10. merwok commented on May 23, 2011

      @merwok
      merwok
      on May 23, 2011
      Member
      More actions

      I’d favor 1) or 2) over 3). Ints are short and very commonly used for flags.

    11. ezio-melotti commented on Sep 5, 2011

      @ezio-melotti
      ezio-melotti
      on Sep 5, 2011
      Member
      More actions

      See also bpo-12888 for an error in the stdlib caused by this.

    12. ezio-melotti
      added
      type-featureA feature request or enhancementA feature request or enhancement
      on Apr 10, 2013
    13. mmilkin commented on Apr 13, 2013

      @mmilkin
      mmilkinmannequin
      on Apr 13, 2013
      Mannequin
      More actions

      I like option #2, and I was thinking of working on it today, poke me if anyone has a problem with this.

    14. mmilkin commented on Apr 13, 2013

      @mmilkin
      mmilkinmannequin
      on Apr 13, 2013
      Mannequin
      More actions

      There is no sane way to issue a warning without changing the signature and we don't want to change the signature without issuing a deprecation warning for the function, so sadly option 3 is the only way for this to work, (Im going to not touch this till ENUMS are merged in.)

    15. 29 remaining items

    16. serhiy-storchaka
      closed this as completedon Aug 17, 2023
    17. tchaikov
      added a commit that references this issue on Sep 27, 2024

      test.py: pass "count" to re.sub() with kwarg

      8b833d8
    18. xemul
      added a commit that references this issue on Sep 30, 2024

      test.py: pass "count" to re.sub() with kwarg

      c3be4a3
    19. paul-elliott-arm
      added a commit that references this issue on Oct 25, 2024

      Remove deprecated use of count as positional arg

      03b11fb
    20. paul-elliott-arm
      added a commit that references this issue on Nov 13, 2024

      Remove deprecated use of count as positional arg

      59ec32a
    21. tchaikov
      added 2 commits that reference this issue on Dec 31, 2024

      test.py: pass "count" to re.sub() with kwarg

      e4a46d6

      test.py: pass "count" to re.sub() with kwarg

      4fb8ee9
    22. avikivity
      added a commit that references this issue on Jan 6, 2025

      test.py: pass "count" to re.sub() with kwarg

      8873a4e
    23. aarongable
      added a commit that references this issue on Feb 25, 2025

      crashpad: fix update.py DeprecationWarning under Python 3.13

      df2f36f
    24. hubot
      added a commit that references this issue on Feb 25, 2025

      Fix Python 3.13 re DeprecationWarning: pass count and flags by keyword

      51eba29
    25. gm4sl
      added a commit that references this issue on Apr 1, 2025

      Fix Python 3.13 re DeprecationWarning: pass count and flags by keyword

      80a21e5
    26. millerdev
      added 3 commits that reference this issue on Apr 8, 2025

      'maxsplit' should not be passed as positional argument

      a0dce04

      'maxsplit' should not be passed as positional argument

      497e4ca

      'maxsplit' should not be passed as positional argument

      5c276d2
    27. lastnameis-borah
      added a commit that references this issue on Feb 2, 2026

      artiq_flash: Fix incorrect re.sub() call

      f54629b
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    • @ezio-melotti
      ezio-melotti

    Labels

    3.7 (EOL)end of lifeend of lifetopic-regextype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.