GeezerVison is showing github.com — gh-103498: argparse.ArgumentParser will always throw instead of exit if exit_on_error=False by JustBeYou · Pull Request #103519 · python/cpython
Conversation
JustBeYou
commented
Apr 13, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Fix for #103498
Summary:
- moved the decision of if we should raise exception or exit to
ArgumentParser.error method based on exit_on_error parameter
- replaced all
raise ArgumentError with self.error() in ArgumentParser
- added a new named parameter to
ArgumentParser.error, namely action=None because raising ArgumentError requires it
- updated the documentation to reflect the change
Note:
- adding a new named parameter breaks the API for classes that inherit
ArgumentParser; a solution to this would be to use **kwargs instead, but seems kind of dirty to me. suggestions appreciated
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
olgarithms and real-yfprojects reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
ghost
commented
Apr 13, 2023
•
edited by ghost
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
All commit authors signed the Contributor License Agreement. 
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
… exit if exit_on_error=False
|
@sobolevn , do you think this is a good fix? I can add tests to this :)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Taking a closer look at the problem, I don't see the proposed fix as suitable anymore. I think that to properly solve the problem with exit_on_error, we have to address the inconsistent error handling in ArgumentParser (raising and calling self.error in multiple places). I will share some opinions on the associated issue, maybe we could move forward somehow.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thank you for your contribution @JustBeYou. I apologize for the fact that this PR was neglected for a long time. The problem has already been solved in another way.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.