Skip to content

Fix -h/-i/-v/-t single-char flags being silently hijacked by user function arguments#661

Open
anishesg wants to merge 1 commit intogoogle:masterfrom
anishesg:fix/ph-issue-238
Open

Fix -h/-i/-v/-t single-char flags being silently hijacked by user function arguments#661
anishesg wants to merge 1 commit intogoogle:masterfrom
anishesg:fix/ph-issue-238

Conversation

@anishesg
Copy link
Copy Markdown

When a user function has a parameter whose name starts with h, i, v, or t
(e.g. headless, interactive, verbose), Fire's shortcut-flag expansion in
_ParseKeywordArgs (fire/core.py) would match a bare -h/-i/-v/-t flag
to that parameter before Fire's own help/interactive/verbose/trace flags had a
chance to handle it. This caused python myfile.py -h to silently set
headless=True instead of showing the help screen.

The root cause is that the single-character shortcut expansion in
_ParseKeywordArgs (around the elif len(key) == 1 branch) had no awareness
of Fire's own reserved single-character flags defined in parser.CreateParser.

The fix introduces a module-level frozenset _FIRE_RESERVED_SINGLE_CHAR_FLAGS
containing {'h', 'i', 'v', 't'} and skips shortcut expansion for those
characters, letting them fall through to remaining_kwargs where
_IsHelpShortcut (and the normal flag-arg parsing path) can process them
correctly. A regression test covering the headless/-h collision case is
included in fire/core_test.py.

Fixes #238

…ction arguments

When a user function has a parameter whose name starts with `h`, `i`, `v`, or `t`

Signed-off-by: anish k <ak8686@princeton.edu>
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.

First-character argument flag is undocumented and behaves strangely when colliding with default options

1 participant