Content-Length: 310383 | pFad | https://github.com/python/cpython/issues/121018

73 argparse.ArgumentParser.parses_args does not honor exit_on_error=False when given unrecognized arguments · Issue #121018 · python/cpython · GitHub
Skip to content

argparse.ArgumentParser.parses_args does not honor exit_on_error=False when given unrecognized arguments #121018

@blhsing

Description

@blhsing

Bug report

Bug description:

As reported in Discourse, even though the documentation on the exit_on_error argument for argparse.ArgumentParser says:

exit_on_error - Determines whether or not ArgumentParser exits with error info when an error occurs. (default: True)

The parse_args method would still exit with error info when there are unrecognized arguments:

import argparse
parser = argparse.ArgumentParser(exit_on_error=False)
try:
    parser.parse_args('invalid arguments'.split())
except argparse.ArgumentError:
    print('ArgumentError caught.')

which outputs:

usage: test.py [-h]
test.py: error: unrecognized arguments: invalid arguments

CPython versions tested on:

3.12, CPython main branch

Operating systems tested on:

Linux, Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Doc issues

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/121018

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy