Skip to content

ArgumentParser.parse_args exits on missing required argument with exit_on_error=False #90598

Closed

Description

@trilader
mannequin
BPO 46440
Nosy @jacobtylerwalls, @trilader
PRs
  • gh-85427: Prevent exits if ArgumentParser.exit_on_error is False #30832
  • Files
  • bug.py
  • 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 2022-02-02.16:52:20.796>
    created_at = <Date 2022-01-19.21:04:30.013>
    labels = ['type-bug', 'library', '3.10']
    title = 'ArgumentParser.parse_args exits on missing required argument with exit_on_error=False'
    updated_at = <Date 2022-02-02.16:52:20.794>
    user = 'https://github.com/trilader'

    bugs.python.org fields:

    activity = <Date 2022-02-02.16:52:20.794>
    actor = 'paul.j3'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-02-02.16:52:20.796>
    closer = 'paul.j3'
    components = ['Library (Lib)']
    creation = <Date 2022-01-19.21:04:30.013>
    creator = 'trilader'
    dependencies = []
    files = ['50567']
    hgrepos = []
    issue_num = 46440
    keywords = ['patch']
    message_count = 2.0
    messages = ['410984', '412376']
    nosy_count = 3.0
    nosy_names = ['paul.j3', 'jacobtylerwalls', 'trilader']
    pr_nums = ['30832']
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46440'
    versions = ['Python 3.10']

    Activity

    1. trilader commented on Jan 19, 2022

      triladermannequin
      MannequinAuthor

      When calling ArgumentParser.parse_args(list_of_things_to_parse) sys.exit gets called even though the parser was constructed with exit_on_error=False. It doesn't matter if the parser has any subparsers added or not.

      The docs say

      Normally, when you pass an invalid argument list to the parse_args()
      method of an ArgumentParser, it will exit with error info.

      If the user would like to catch errors manually, the feature can be
      enabled by setting exit_on_error to False:
      [example code follows]

      The docs make me believe what I'm trying to do should work.
      I've attached a minimal working example to show what happens (with and without subparsers).

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Jan 19, 2022
    3. paulj3 commented on Feb 2, 2022

      paulj3mannequin
      Mannequin

      Duplicate of https://bugs.python.org/issue41255

      Argparse.parse_args exits on unrecognized option with exit_on_error=False

    4. 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.10 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions