-
Notifications
You must be signed in to change notification settings - Fork 99
fix(parser): escape unescaped '%' in help text for Python 3.14 argpar… #299
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
YangAn-microsoft
wants to merge
1
commit into
microsoft:dev
Choose a base branch
from
YangAn-microsoft:fix/argparse-unescaped-percent-help
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may not be a good solution to hack into an
argparse.Action, as it may cause other unexpected side effects or failures asargparseactually expects%in the help message to be escaped.Would it be possible to use
help_string % paramslikeargparsewhen printing the help message?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. I agree this area needs to be conservative.
I evaluated applying argparse-style help interpolation in Knack, but I believe that would be a broader behavior change, not just a percent-sign fix.
On the argparse.Action concern specifically: the current fix is intentionally scoped to help text only. It does not modify parsing semantics such as type, nargs, choices, required, defaults, or validators. It only escapes percent signs to pass Python 3.14 add_argument validation, then restores original help text so displayed help remains unchanged.
Given that, I believe the current approach is the lowest-risk compatibility fix for Python 3.14 without forcing broad migrations and contract sync.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the cost of changing it to
_expand_help? If%%is the right way, we should not restore to a deprecated method.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the question. The cost of switching to _expand_help is ecosystem migration and rollout risk.
It changes the contract for help text: literal % must be escaped as %%.
That means existing help strings with unescaped % (in both azure-cli and extensions) need to be updated.
This cannot be treated as an isolated Knack change. It needs coordinated rollout with the help-text updates.
If rollout is not coordinated:
I agree extension owners may not need direct notification if the check is enforced by test/CI, because unescaped % should fail validation and be caught. But that still means this is a breaking contract change and requires planned migration, not a narrow compatibility fix.
That is why I treated the current patch as a compatibility fix and considered _expand_help migration a separate, broader change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this PR is not changing how knack supports %-formatting (not supported). Some problems may occur:
%%asargparserequested, it will be printed as%%, not%.%(...), it will not be %-formatted.An alternative solution:
%(or%%in th help string, leave the string as is.%to%%, like AWS CLI did (Add support for Python 3.14 aws/aws-cli#9790).The bottom line is that knack should support %-formatting when printing the help message, thus not rejecting correct usages according to
argparse.