-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
argparse.ArgumentParser.parses_args does not honor exit_on_error=False when given unrecognized arguments #121018
Comments
…raises instead of exiting when given unrecognized arguments (GH-121019)
…False raises instead of exiting when given unrecognized arguments (pythonGH-121019) (cherry picked from commit 0654336) Co-authored-by: blhsing <[email protected]>
…False raises instead of exiting when given unrecognized arguments (pythonGH-121019) (cherry picked from commit 0654336) Co-authored-by: blhsing <[email protected]>
…=False raises instead of exiting when given unrecognized arguments (GH-121019) (GH-121032) (cherry picked from commit 0654336) Co-authored-by: blhsing <[email protected]>
…=False raises instead of exiting when given unrecognized arguments (GH-121019) (GH-121031) (cherry picked from commit 0654336) Co-authored-by: blhsing <[email protected]>
…rror=False * parse_intermixed_args() now raises ArgumentError instead of calling error() if exit_on_error is false. * Internal code now always raises ArgumentError instead of calling error(). It is then caught at higher level and error() is called if exit_on_error is true.
Actually, this is more complex issue. In most cases it can be replaced with In some cases ValueError may be more appropriate exception than ArgumentError, but this is another issue. |
Ah yes good catch. I think |
On second thought, I think it may be cleaner to simply put the |
…alse (GH-121056) * parse_intermixed_args() now raises ArgumentError instead of calling error() if exit_on_error is false. * Internal code now always raises ArgumentError instead of calling error(). It is then caught at the higher level and error() is called if exit_on_error is true.
Ah you're right. I forgot to search for prior bug reports before filing mine. Sorry.
Good point. Will keep the current approach then. Thanks! |
…it_on_error=False (pythonGH-121056) * parse_intermixed_args() now raises ArgumentError instead of calling error() if exit_on_error is false. * Internal code now always raises ArgumentError instead of calling error(). It is then caught at the higher level and error() is called if exit_on_error is true. (cherry picked from commit 81a654a) Co-authored-by: Serhiy Storchaka <[email protected]>
…it_on_error=False (pythonGH-121056) * parse_intermixed_args() now raises ArgumentError instead of calling error() if exit_on_error is false. * Internal code now always raises ArgumentError instead of calling error(). It is then caught at the higher level and error() is called if exit_on_error is true. (cherry picked from commit 81a654a) Co-authored-by: Serhiy Storchaka <[email protected]>
…error=False (GH-121056) (GH-121129) * parse_intermixed_args() now raises ArgumentError instead of calling error() if exit_on_error is false. * Internal code now always raises ArgumentError instead of calling error(). It is then caught at the higher level and error() is called if exit_on_error is true. (cherry picked from commit 81a654a)
…error=False (GH-121056) (GH-121128) * parse_intermixed_args() now raises ArgumentError instead of calling error() if exit_on_error is false. * Internal code now always raises ArgumentError instead of calling error(). It is then caught at the higher level and error() is called if exit_on_error is true. (cherry picked from commit 81a654a)
…False raises instead of exiting when given unrecognized arguments (pythonGH-121019)
…rror=False (pythonGH-121056) * parse_intermixed_args() now raises ArgumentError instead of calling error() if exit_on_error is false. * Internal code now always raises ArgumentError instead of calling error(). It is then caught at the higher level and error() is called if exit_on_error is true.
…False raises instead of exiting when given unrecognized arguments (pythonGH-121019)
…rror=False (pythonGH-121056) * parse_intermixed_args() now raises ArgumentError instead of calling error() if exit_on_error is false. * Internal code now always raises ArgumentError instead of calling error(). It is then caught at the higher level and error() is called if exit_on_error is true.
…False raises instead of exiting when given unrecognized arguments (pythonGH-121019)
…rror=False (pythonGH-121056) * parse_intermixed_args() now raises ArgumentError instead of calling error() if exit_on_error is false. * Internal code now always raises ArgumentError instead of calling error(). It is then caught at the higher level and error() is called if exit_on_error is true.
Bug report
Bug description:
As reported in Discourse, even though the documentation on the
exit_on_error
argument forargparse.ArgumentParser
says:The
parse_args
method would still exit with error info when there are unrecognized arguments:which outputs:
CPython versions tested on:
3.12, CPython main branch
Operating systems tested on:
Linux, Windows
Linked PRs
The text was updated successfully, but these errors were encountered: