classification
Title: argparse.ArgumentParser does not raise on duplicated subparsers, even though it does on duplicated flags
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Antony.Lee, paul.j3, rhettinger
Priority: normal Keywords: patch

Created on 2020-02-21 18:20 by Antony.Lee, last changed 2020-02-22 11:04 by Antony.Lee.

Pull Requests
URL Status Linked Edit
PR 18605 open Antony.Lee, 2020-02-22 11:04
Messages (3)
msg362421 - (view) Author: Antony Lee (Antony.Lee) * Date: 2020-02-21 18:20
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.
msg362428 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-02-21 20:34
Would you like to work-up a patch to fix this?
msg362458 - (view) Author: Antony Lee (Antony.Lee) * Date: 2020-02-22 11:04
Sure, https://github.com/python/cpython/pull/18605 it is.
History
Date User Action Args
2020-02-22 11:04:34Antony.Leesetmessages: + msg362458
2020-02-22 11:04:01Antony.Leesetkeywords: + patch
stage: patch review
pull_requests: + pull_request17971
2020-02-21 20:34:23rhettingersetmessages: + msg362428
2020-02-21 18:40:20xtreaksetnosy: + rhettinger, paul.j3
2020-02-21 18:20:54Antony.Leecreate