gh-125355: Rewrite parse_intermixed_args() in argparse#125356
Merged
serhiy-storchaka merged 6 commits intopython:mainfrom Oct 22, 2024
Merged
gh-125355: Rewrite parse_intermixed_args() in argparse#125356serhiy-storchaka merged 6 commits intopython:mainfrom
serhiy-storchaka merged 6 commits intopython:mainfrom
Conversation
* The parser is no longer temporary modified and can be used concurrently. * Default values are no long handled twice. * Report about missed arguments now contains names of all required optional and positional arguments. * Unknown options can be intermixed with positionals in parse_known_intermixed_args().
| parser.parse_intermixed_args([]) | ||
| msg = str(cm.exception) | ||
| self.assertNotRegex(msg, 'req_pos') | ||
| self.assertRegex(msg, 'req_pos') |
Member
Author
There was a problem hiding this comment.
This was a bug.
Comment on lines
-6284
to
-6420
| self.assertEqual(NS(bar='y', cmd='cmd', foo='x', rest=[1]), args) | ||
| self.assertEqual(['--error', '2', '3'], extras) |
Member
Author
There was a problem hiding this comment.
I think that was a bug. The result was different depending on the position of unknown option.
Comment on lines
-6330
to
-6469
| parser = ErrorRaisingArgumentParser(prog='PROG') | ||
| parser.add_argument('--foo', nargs="*") | ||
| parser.add_argument('foo') | ||
| with self.assertWarns(UserWarning): | ||
| parser.parse_intermixed_args(['hello', '--foo']) |
Member
Author
Comment on lines
-2487
to
-2510
| if (hasattr(namespace, action.dest) | ||
| and getattr(namespace, action.dest)==[]): | ||
| from warnings import warn | ||
| warn('Do not expect %s in %s' % (action.dest, namespace)) | ||
| delattr(namespace, action.dest) |
Member
Author
There was a problem hiding this comment.
I do not understand this code. There were no tests, and the purpose is not clear to me. @hpaulj, @bitdancer, could you shed some light on this?
…rmixed-args' into argparse-parse-intermixed-args
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Oct 22, 2024
…H-125356) * The parser no longer changes temporarily during parsing. * Default values are not processed twice. * Required mutually exclusive groups containing positional arguments are now supported. * The missing arguments report now includes the names of all required optional and positional arguments. * Unknown options can be intermixed with positional arguments in parse_known_intermixed_args(). (cherry picked from commit 759a54d) Co-authored-by: Serhiy Storchaka <[email protected]>
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
|
GH-125834 is a backport of this pull request to the 3.13 branch. |
serhiy-storchaka
added a commit
that referenced
this pull request
Oct 22, 2024
) (GH-125834) * The parser no longer changes temporarily during parsing. * Default values are not processed twice. * Required mutually exclusive groups containing positional arguments are now supported. * The missing arguments report now includes the names of all required optional and positional arguments. * Unknown options can be intermixed with positional arguments in parse_known_intermixed_args(). (cherry picked from commit 759a54d) Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka
added a commit
to serhiy-storchaka/cpython
that referenced
this pull request
Oct 22, 2024
…ythonGH-125356) * The parser no longer changes temporarily during parsing. * Default values are not processed twice. * Required mutually exclusive groups containing positional arguments are now supported. * The missing arguments report now includes the names of all required optional and positional arguments. * Unknown options can be intermixed with positional arguments in parse_known_intermixed_args(). (cherry picked from commit 759a54d) Co-authored-by: Serhiy Storchaka <[email protected]>
|
GH-125839 is a backport of this pull request to the 3.12 branch. |
serhiy-storchaka
added a commit
that referenced
this pull request
Oct 22, 2024
) (GH-125839) * The parser no longer changes temporarily during parsing. * Default values are not processed twice. * Required mutually exclusive groups containing positional arguments are now supported. * The missing arguments report now includes the names of all required optional and positional arguments. * Unknown options can be intermixed with positional arguments in parse_known_intermixed_args(). (cherry picked from commit 759a54d)
ebonnal
pushed a commit
to ebonnal/cpython
that referenced
this pull request
Jan 12, 2025
…H-125356) * The parser no longer changes temporarily during parsing. * Default values are not processed twice. * Required mutually exclusive groups containing positional arguments are now supported. * The missing arguments report now includes the names of all required optional and positional arguments. * Unknown options can be intermixed with positional arguments in parse_known_intermixed_args().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Uh oh!
There was an error while loading. Please reload this page.