Title: Fix short flags being swallowed by **kwargs (fixes #454) by shivamtiwari3 · Pull Request #652 · google/python-fire · GitHub
Open Graph Title: Fix short flags being swallowed by **kwargs (fixes #454) by shivamtiwari3 · Pull Request #652 · google/python-fire
X Title: Fix short flags being swallowed by **kwargs (fixes #454) by shivamtiwari3 · Pull Request #652 · google/python-fire
Description: Summary Fixes #454. Short flags like -f and -s were being stored directly in **kwargs (as {'f': 'hello', 's': 'world'}) instead of being expanded to their matching positional argument names (first_arg, second_arg) when a function accepts **kwargs. Problem In _ParseKeywordArgs (core.py:887), the condition was: if (key in fn_args or (is_bool_syntax and key.startswith('no') and key[2:] in fn_args) or fn_keywords): keyword = key elif len(key) == 1: # single-char shortcut lookup ... When fn_keywords is truthy (i.e. the function has **kwargs), the first branch fires immediately, setting keyword = key (the raw single character). The shortcut lookup in the elif branch is never reached. Solution Restructured the conditions so single-char shortcut expansion against fn_args is always attempted first. fn_keywords is only used as a fallback when no fn_arg matches the single character: if key in fn_args or (...noXxx... in fn_args): keyword = key elif len(key) == 1: matching_fn_args = [arg for arg in fn_args if arg[0] == key] if len(matching_fn_args) == 1: keyword = matching_fn_args[0] elif len(matching_fn_args) > 1: raise FireError(...) elif fn_keywords: # ← fallback: no fn_arg match, accept into **kwargs keyword = key elif fn_keywords: keyword = key Multi-character unrecognised flags still fall through to **kwargs as before. Testing Added fn_with_defaults_and_kwargs to test_components.py Added testSingleCharFlagParsingWithKwargs to fire_test.py covering: -f=hello -s=world → ('hello', 'world', {}) -f hello -s world → ('hello', 'world', {}) unrecognised --unknown_key=42 → still forwarded to **kwargs Command: python3 -m pytest fire/ --ignore=fire/docstrings_fuzz_test.py --ignore=fire/parser_fuzz_test.py 261 tests pass, 0 failures Checklist Fixes the reported issue Existing behaviour unchanged (no regressions) Tests added All 261 tests pass Code style matches project conventions
Open Graph Description: Summary Fixes #454. Short flags like -f and -s were being stored directly in **kwargs (as {'f': 'hello', 's': 'world'}) instead of being expanded to their matching p...
X Description: Summary Fixes #454. Short flags like -f and -s were being stored directly in **kwargs (as {'f': 'hello', 's': 'world'}) instead of be...
Opengraph URL: https://github.com/google/python-fire/pull/652
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:f7bee21b-c147-5e67-58f3-e3460f3f6d1d |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D54E:A825:E6D1B9:14FB538:6A4E2D73 |
| html-safe-nonce | 834bcbcdb7f0fc5740c6a9adcdbe0ed73ad136ef5cbfabcd6becefbcc8de0b2a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENTRFOkE4MjU6RTZEMUI5OjE0RkI1Mzg6NkE0RTJENzMiLCJ2aXNpdG9yX2lkIjoiNDc4NDg5MTEzMzQ1MTcwOTgxMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1bded75d8b2f89291d1997178c9df25b6ab41aabae8e2fbaa21cc41dfbf73113 |
| hovercard-subject-tag | pull_request:3376775717 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/google/python-fire/pull/652/files |
| twitter:image | https://avatars.githubusercontent.com/u/33183708?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/33183708?s=400&v=4 |
| og:image:alt | Summary Fixes #454. Short flags like -f and -s were being stored directly in **kwargs (as {'f': 'hello', 's': 'world'}) instead of being expanded to their matching p... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 030096ee0db095447bfe77409d33bfac127ca7128299c58deef27c52eaa1b1f0 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/google/python-fire git https://github.com/google/python-fire.git |
| octolytics-dimension-user_id | 1342004 |
| octolytics-dimension-user_login | |
| octolytics-dimension-repository_id | 82729529 |
| octolytics-dimension-repository_nwo | google/python-fire |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 82729529 |
| octolytics-dimension-repository_network_root_nwo | google/python-fire |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d9dd20d38f8ae3c4cb6b597807431db300d0bd2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width