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
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()

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()

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, it is.
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