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

argparse.ArgumentParser does not raise on duplicated subparsers, even though it does on duplicated flags #83897

Closed
anntzer mannequin opened this issue Feb 21, 2020 · 6 comments
Labels
3.9 only security fixes stdlib Python modules in the Lib dir

Comments

@anntzer
Copy link
Mannequin

anntzer mannequin commented Feb 21, 2020

BPO 39716
Nosy @rhettinger, @anntzer
PRs
  • gh-83897: Raise on conflicting subparser names. #18605
  • 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 = None
    created_at = <Date 2020-02-21.18:20:54.496>
    labels = ['library', '3.9']
    title = 'argparse.ArgumentParser does not raise on duplicated subparsers, even though it does on duplicated flags'
    updated_at = <Date 2020-02-22.11:04:34.546>
    user = 'https://github.com/anntzer'

    bugs.python.org fields:

    activity = <Date 2020-02-22.11:04:34.546>
    actor = 'Antony.Lee'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2020-02-21.18:20:54.496>
    creator = 'Antony.Lee'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39716
    keywords = ['patch']
    message_count = 3.0
    messages = ['362421', '362428', '362458']
    nosy_count = 3.0
    nosy_names = ['rhettinger', 'paul.j3', 'Antony.Lee']
    pr_nums = ['18605']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue39716'
    versions = ['Python 3.9']

    @anntzer
    Copy link
    Mannequin Author

    anntzer mannequin commented Feb 21, 2020

    If one tries to add twice the same flag to an ArgumentParser, one gets a helpful exception:

        from argparse import ArgumentParser
        p = ArgumentParser()
        p.add_argument("--foo")
        p.add_argument("--foo")

    results in

    argparse.ArgumentError: argument --foo: conflicting option string: --foo
    

    However, adding twice the same subparser raises no exception:

        from argparse import ArgumentParser
        p = ArgumentParser()
        sp = p.add_subparsers()
        sp.add_parser("foo")
        sp.add_parser("foo")

    even though the two subparsers shadow one another in the same way as two identical flags.

    @anntzer anntzer mannequin added 3.9 only security fixes stdlib Python modules in the Lib dir labels Feb 21, 2020
    @rhettinger
    Copy link
    Contributor

    Would you like to work-up a patch to fix this?

    @anntzer
    Copy link
    Mannequin Author

    anntzer mannequin commented Feb 22, 2020

    Sure, #18605 it is.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    kkalinowski-reef added a commit to kkalinowski-reef/B2_Command_Line_Tool that referenced this issue Nov 11, 2022
    In 3.11 a bug with duplicated names/aliases of subparsers was fixed in
    python/cpython#83897. This leads to an argument
    error being raised whenever a duplicate is found. In previous python
    versions additional parsers were just overridden without a warning.
    @ppolewicz
    Copy link

    ppolewicz commented Nov 11, 2022

    Please note that this issue is labeled as 3.9 and fix for it was submitted in February 2020, but the fix was actually released with 3.11

    @terryjreedy
    Copy link
    Member

    @ppolewicz PRs are nearly always merged into main and only sometimes backported. Tracker version labels indicate the version(s) reported for, not necessarily the versions patched. Since we moved the repository to github, PR titles indicate the version(s) actually patched (with 'main' the default). The tracker move to github messed up merge reporting for old PRs. I repointed the PR for this issue to the gh number so it is listed immediately above.

    @serhiy-storchaka
    Copy link
    Member

    This was actually a duplicate of #59061.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes stdlib Python modules in the Lib dir
    Projects
    Status: Doc issues
    Development

    No branches or pull requests

    4 participants