GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@JustBeYou JustBeYou commented Apr 13, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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
  • Issue: argparse exits on error even when exit_on_error=False #103498

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
All reactions
  • 👍 2 reactions
@bedevere-bot

bedevere-bot commented Apr 13, 2023

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot mentioned this pull request Apr 13, 2023
argparse exits on error even when exit_on_error=False #103498
Closed
@bedevere-bot bedevere-bot added the awaiting review label Apr 13, 2023
@ghost

ghost commented Apr 13, 2023 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JustBeYou
JustBeYou force-pushed the gh-103498 branch 2 times, most recently from ec4f0b7 to 1b3c821 Compare April 13, 2023 21:35
@JustBeYou
JustBeYou marked this pull request as ready for review April 13, 2023 21:38
@JustBeYou
pythongh-103498: argparse.ArgumentParser will always throw instead of…
64b87d6
… exit if exit_on_error=False
@JustBeYou
JustBeYou force-pushed the gh-103498 branch from 1b3c821 to 64b87d6 Compare April 13, 2023 22:10
@JustBeYou
Merge branch 'main' into pythongh-103498
d97c16a
@jacobtylerwalls jacobtylerwalls mentioned this pull request Apr 15, 2023
gh-85427: Prevent exits if ArgumentParser.exit_on_error is False #30832
Closed
@olgarithms

olgarithms commented Apr 24, 2023

Copy link
Copy Markdown
Contributor

@sobolevn , do you think this is a good fix? I can add tests to this :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JustBeYou

JustBeYou commented May 4, 2023

Copy link
Copy Markdown
Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Jun 28, 2024

Copy link
Copy Markdown
Member

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka serhiy-storchaka closed this Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

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.

4 participants

@JustBeYou @bedevere-bot @olgarithms @serhiy-storchaka
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.