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-85427: Prevent exits if `ArgumentParser.exit_on_error` is False by jacobtylerwalls · Pull Request #30832 · python/cpython

Conversation

@jacobtylerwalls

@jacobtylerwalls jacobtylerwalls commented Jan 23, 2022 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

bpo-41255

The exit_on_error docs read:

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

From this, I agree with the reporter that all exit paths should raise an exception rather than exit.

https://bugs.python.org/issue46440

Fixes #85427

  • Issue: Argparse.parse_args exits on unrecognized option with exit_on_error=False #85427

Sorry, something went wrong.

Uh oh!

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

ollandos, olgarithms, josealdaco, psasselum, Pierre-Sassoulas, and JoakimJoensuu reacted with heart emoji
All reactions
  • ❤️ 6 reactions
@jacobtylerwalls
bpo-46440: Prevent all exits if ArgumentParser.exit_on_error is False
a2a1462
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Jan 23, 2022
@JelleZijlstra

JelleZijlstra commented Jan 24, 2022

Copy link
Copy Markdown
Member

Looking inside _parse_known_args, I see some error paths doing raise ArgumentError and others calling self.error, without any apparent pattern. If they all did raise ArgumentError, that would fix this bug.

jacobtylerwalls reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@jacobtylerwalls
Make all error paths raise ArgumentError
0fc30d3
@JelleZijlstra

JelleZijlstra commented Jan 24, 2022

Copy link
Copy Markdown
Member

There are other calls to self.error elsewhere in the class that may be invoked from _parse_known_args, so this still leaves some paths where it may exit. In that sense, your original solution was more robust. I am honestly not sure which solution is better.

All reactions

Sorry, something went wrong.

Uh oh!

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

@jacobtylerwalls
Extend solution
f3e173c
@jacobtylerwalls

jacobtylerwalls commented Jan 29, 2022 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

I found a duplicate with some more discussion: bpo-41255.

From the penultimate comment:

I'm not sure I like the idea of changing the exit or error methods since they have a a clear purpose and don't need to be repurposed to also include error handling. It seems to me that adding checks to self.exit_on_error in _parse_known_args to handle the missing required arguments and in parse_args to handle unknown arguments is probably a quick and clean solution.

All reactions

Sorry, something went wrong.

Uh oh!

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

jacobtylerwalls added 2 commits January 28, 2022 23:37
@jacobtylerwalls
Guard according to exit_on_error
10c748a
@jacobtylerwalls
Additional regression tests
7b83cf6
@jacobtylerwalls jacobtylerwalls changed the title bpo-46440: Prevent all exits if ArgumentParser.exit_on_error is False bpo-46440: Prevent exits if ArgumentParser.exit_on_error is False Jan 29, 2022
@jacobtylerwalls jacobtylerwalls changed the title bpo-46440: Prevent exits if ArgumentParser.exit_on_error is False bpo-41255: Prevent exits if ArgumentParser.exit_on_error is False Feb 5, 2022
@jacobtylerwalls

jacobtylerwalls commented Feb 5, 2022

Copy link
Copy Markdown
Contributor Author

Alternative to #27295

All reactions

Sorry, something went wrong.

Uh oh!

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

@matthewhughes934 matthewhughes934 mannequin mentioned this pull request Apr 10, 2022
Argparse.parse_args exits on unrecognized option with exit_on_error=False #85427
Closed
@jacobtylerwalls
Merge branch 'main' into argparse-exit-on-error
742bede
@AA-Turner

AA-Turner commented Jun 7, 2022

Copy link
Copy Markdown
Member

Backref to #85427 (@jacobtylerwalls please could you update the title to start with gh-85427?).

A

jacobtylerwalls reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@AA-Turner AA-Turner added type-bug An unexpected behavior, bug, or error awaiting review stdlib Standard Library Python modules in the Lib/ directory and removed CLA signed labels Jun 7, 2022
@jacobtylerwalls jacobtylerwalls changed the title bpo-41255: Prevent exits if ArgumentParser.exit_on_error is False gh-85427: Prevent exits if ArgumentParser.exit_on_error is False Jun 7, 2022
@jacobtylerwalls jacobtylerwalls mentioned this pull request Apr 15, 2023
argparse exits on error even when exit_on_error=False #103498
Closed
@jacobtylerwalls

jacobtylerwalls commented Apr 15, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

@JelleZijlstra Forgive the ping! I just I noticed a duplicate issue (#103498) and PR (#103519) rolled in for this. Do you have a reviewer you might recommend to take a look?

Where we left off was comparing 1.) guarding the calls to self.error() or 2.) altering self.error() itself.

I am honestly not sure which solution is better.

I was somewhat convinced by the comment quoted in #30832 (comment). Plus it's more backwards compatible to leave error() alone. Appreciate any advice, as you may be able!

All reactions

Sorry, something went wrong.

Uh oh!

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

@JelleZijlstra

JelleZijlstra commented Apr 15, 2023

Copy link
Copy Markdown
Member

@sobolevn and @barneygale expressed some interest in argparse issues recently. I don't feel strongly here but I'll try to find some time to read up again and form an opinion.

jacobtylerwalls reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

jacobtylerwalls added 2 commits April 14, 2023 22:43
@jacobtylerwalls
Merge branch 'main' into argparse-exit-on-error
e41aa7c
@jacobtylerwalls
Extend solution to parse_intermixed_args()
7e16f62
@sobolevn

sobolevn commented Apr 15, 2023

Copy link
Copy Markdown
Member

Also closes: #103498

All reactions

Sorry, something went wrong.

Uh oh!

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

@sobolevn

sobolevn commented Apr 15, 2023

Copy link
Copy Markdown
Member

So, we have at least two PRs that do opposite things.
This PR uses raise ArgumentError: #30832
And the alternative uses self.error() instead: #103519

Now, we need to decide what is better :)

jacobtylerwalls, JustBeYou, psasselum, Pierre-Sassoulas, and pseudokawaii reacted with thumbs up emoji
All reactions
  • 👍 5 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 @jacobtylerwalls. I apologize for the fact that this PR was neglected for a long time. The problem has already been solved in a way similar to the way proposed in your PR.

jacobtylerwalls reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

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
@jacobtylerwalls
jacobtylerwalls deleted the argparse-exit-on-error branch June 28, 2024 14:50
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 stdlib Standard Library Python modules in the Lib/ directory type-bug An unexpected behavior, bug, or error

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Argparse.parse_args exits on unrecognized option with exit_on_error=False

Uh oh!

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

6 participants

@jacobtylerwalls @JelleZijlstra @AA-Turner @sobolevn @serhiy-storchaka @the-knights-who-say-ni
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 01402503 — 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.