Skip to content

re functions: convert count and flags parameters to keyword-only? #74258

Closed

Description

@vstinner
BPO 30072
Nosy @vstinner, @serhiy-storchaka
Superseder
  • bpo-11957: re.sub confusion between count and flags args
  • 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 = None
    closed_at = <Date 2017-04-14.12:45:06.524>
    created_at = <Date 2017-04-14.12:36:04.691>
    labels = ['3.7', 'library']
    title = 're functions: convert count and flags parameters to keyword-only?'
    updated_at = <Date 2017-04-14.12:45:06.523>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2017-04-14.12:45:06.523>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-04-14.12:45:06.524>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2017-04-14.12:36:04.691>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30072
    keywords = []
    message_count = 2.0
    messages = ['291650', '291653']
    nosy_count = 2.0
    nosy_names = ['vstinner', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '11957'
    type = None
    url = 'https://bugs.python.org/issue30072'
    versions = ['Python 3.7']

    Activity

    1. vstinner commented on Apr 14, 2017

      @vstinner
      MemberAuthor

      The re API seems commonly misused. Example passing a re flag to re.sub():

      >>> re.sub("A", "B", "ahah", re.I)
      'ahah'

      No error, no warning, but it doesn't work. Oh, sub has 5 paramters, no 4...

      I suggest to convert count and flags to keyword-only parameters. To not break the world, especially legit code passing the count parameter as a position argument, an option is to have a deprecation period if these two parameters are passed a positional-only parameter.

      --

      Another option would be to rely on the fact that re flags are now enums instead of raw integers, and so add basic type check...

      Is there are risk of applications using re flags serialized by pickle from Pyhon < 3.6 and so getting integers?

      Maybe the check should only be done if flags are passing as positional-only argument... but the implementation of such check seems may be overkill for such simple and performance-critical function, no?

      See issue bpo-30067 for a recent bug in the Python stdlib!

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Apr 14, 2017
    3. changed the title [-]re function: convert count and flags parameters to keyword-only?[/-] [+]re functions: convert count and flags parameters to keyword-only?[/+] on Apr 14, 2017
    4. serhiy-storchaka commented on Apr 14, 2017

      @serhiy-storchaka
      Member

      This is a duplicate of bpo-11957.

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

    No one assigned

      Labels

      3.7 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions