Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Closed
Description
Bug report
Bug description:
As reported inDiscourse, even though the documentation on theexit_on_error argument forargparse.ArgumentParser says:
exit_on_error- Determines whether or notArgumentParserexits with error info when an error occurs. (default:True)
Theparse_args method would still exit with error info when there are unrecognized arguments:
importargparseparser=argparse.ArgumentParser(exit_on_error=False)try:parser.parse_args('invalid arguments'.split())exceptargparse.ArgumentError:print('ArgumentError caught.')
which outputs:
usage: test.py [-h]test.py: error: unrecognized arguments: invalid argumentsCPython versions tested on:
3.12, CPython main branch
Operating systems tested on:
Linux, Windows
Linked PRs
- gh-121018: ensure ArgumentParser.parse_args with exit_on_error=False raises instead of exiting when given unrecognized arguments #121019
- [3.12] gh-121018: Ensure ArgumentParser.parse_args with exit_on_error=False raises instead of exiting when given unrecognized arguments (GH-121019) #121031
- [3.13] gh-121018: Ensure ArgumentParser.parse_args with exit_on_error=False raises instead of exiting when given unrecognized arguments (GH-121019) #121032
- gh-121018: Fix more cases of exiting in argparse when exit_on_error=False #121056
- [3.13] gh-121018: Fix more cases of exiting in argparse when exit_on_error=False (GH-121056) #121128
- [3.12] gh-121018: Fix more cases of exiting in argparse when exit_on_error=False (GH-121056) #121129
- gh-121018: Fix typo in NEWS entry #121510
- [3.12] gh-121018: Fix typo in NEWS entry (GH-121510) #121516
Metadata
Metadata
Assignees
Projects
Status
Doc issues