Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-125355: Rewrite parse_intermixed_args() in argparse#125356

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commentedOct 12, 2024
edited
Loading

  • 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().

* 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')
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

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)
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

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')
withself.assertWarns(UserWarning):
parser.parse_intermixed_args(['hello','--foo'])
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This test was added years after implementing this feature (see9efaff5/#103570) just to increase coverage. I am not sure that it tests the right case, and I do not understand why the warning was emitted at first place.

Comment on lines -2487 to -2510
if (hasattr(namespace,action.dest)
andgetattr(namespace,action.dest)==[]):
fromwarningsimportwarn
warn('Do not expect %s in %s'% (action.dest,namespace))
delattr(namespace,action.dest)
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

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?

@savannahostrowskisavannahostrowski linked an issueOct 18, 2024 that may beclosed by this pull request
@serhiy-storchakaserhiy-storchaka marked this pull request as ready for reviewOctober 21, 2024 20:03
@serhiy-storchakaserhiy-storchakaenabled auto-merge (squash)October 22, 2024 10:31
@serhiy-storchakaserhiy-storchaka added needs backport to 3.12only security fixes needs backport to 3.13bugs and security fixes labelsOct 22, 2024
@serhiy-storchakaserhiy-storchaka merged commit759a54d intopython:mainOct 22, 2024
37 checks passed
@miss-islington-app
Copy link

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 requestOct 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 commit759a54d)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@miss-islington-app
Copy link

Sorry,@serhiy-storchaka, I could not cleanly backport this to3.12 due to a conflict.
Please backport usingcherry_picker on command line.

cherry_picker 759a54d28ffe7eac8c23917f5d3dfad8309856be 3.12

@bedevere-app
Copy link

GH-125834 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelOct 22, 2024
serhiy-storchaka added a commit that referenced this pull requestOct 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 commit759a54d)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull requestOct 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 commit759a54d)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app
Copy link

GH-125839 is a backport of this pull request to the3.12 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.12only security fixes labelOct 22, 2024
serhiy-storchaka added a commit that referenced this pull requestOct 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 commit759a54d)
ebonnal pushed a commit to ebonnal/cpython that referenced this pull requestJan 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().
@serhiy-storchakaserhiy-storchaka deleted the argparse-parse-intermixed-args branchJanuary 16, 2025 08:00
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Rewrite parse_intermixed_args() in argparse

1 participant

@serhiy-storchaka

[8]ページ先頭

©2009-2025 Movatter.jp