Skip to content

{Misc.} Fix help % token handling for Python 3.14 argparse compatibility#300

Open
YangAn-microsoft wants to merge 1 commit intomicrosoft:devfrom
YangAn-microsoft:fix/help-token-expansion-v2
Open

{Misc.} Fix help % token handling for Python 3.14 argparse compatibility#300
YangAn-microsoft wants to merge 1 commit intomicrosoft:devfrom
YangAn-microsoft:fix/help-token-expansion-v2

Conversation

@YangAn-microsoft
Copy link
Copy Markdown

Summary

This PR fixes Knack help rendering for %-based help strings to keep behavior stable with Python 3.14 argparse validation.

Why this is needed (Python 3.14)

Python 3.14 argparse performs stricter help-format validation.
Help text containing unescaped literal % can raise formatting errors during help processing.
Since Knack renders help through custom paths, we must handle these cases safely while preserving argparse placeholder semantics.

What changed

  1. Added safe % sanitization for argparse-facing help text.
  2. Expanded argparse placeholders in Knack-rendered help output.
  3. Added safe fallback behavior so malformed/literal % does not crash help rendering.
  4. Added/updated tests for:
    • %(default)s
    • %(prog)s
    • %%
    • single % fallback behavior

Resulting behavior

  1. %(default)s expands to the argument default value.
  2. %(prog)s expands to the parser program string.
  3. %% is rendered as %.
  4. single % does not crash and is shown as %.

Validation

  1. Targeted token tests passed.
  2. Full Knack test suite passed on Python 3.14 (245 passed).
  3. Azure CLI help-path checks with local Knack changes completed without parser/help crashes.

Scope

This is a focused compatibility and robustness fix for help rendering behavior under Python 3.14.

@YangAn-microsoft YangAn-microsoft marked this pull request as ready for review April 29, 2026 03:21
@YangAn-microsoft YangAn-microsoft changed the title Fix help % token handling for Python 3.14 argparse compatibility {Misc.} Fix help % token handling for Python 3.14 argparse compatibility Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant