[bug] short flags/arguments does not work with `**kwargs`
还没有人认领这个 Issue。
评估
调研方向
运行 issue 中的两个 Python 示例,并比较有无 kwargs 时短选项的行为。然后跟踪 Python Fire 对短选项和关键字参数的参数解析过程。完成标准是:-f 和 -s 填充 first_arg 和 second_arg,同时无关的 flag 仍出现在 kwargs 中,并且两个情况都有回归测试覆盖。
由索引模型根据 Issue 内容生成。
描述
Description:
Short flags/arguments (e.g. -u for --username) does not work with **kwargs
Example that works OK:
The following example works ok:
import fire
def cli(first_arg="left", second_arg="right"):
"""Prints the 2 arguments separated by bar
Parameters
----------
first_arg : str
the first arg
second_arg : str
the second arg
"""
print(f"{first_arg} | {second_arg}" )
if __name__ == '__main__':
fire.Fire(cli)
Help output
❯ python .\example.py -- --help
NAME
example.py - Prints the 2 arguments separated by bar
SYNOPSIS
example.py <flags>
DESCRIPTION
Prints the 2 arguments separated by bar
FLAGS
-f, --first_arg=FIRST_ARG
Default: 'left'
the first arg
-s, --second_arg=SECOND_ARG
Default: 'right'
the second arg
Usage with short flags
❯ python .\example.py -f="hello" -s="word"
hello | word
Example that does not work:
The following next example does not work with short flags, even when they are showing on the help output.
It is using **kwargs. It seems the short flags are going to the **kwargs dictionary.
import fire
def cli(first_arg="left", second_arg="right", **kwargs):
"""Prints the 2 arguments separated by bar
Parameters
----------
first_arg : str
the first arg
second_arg : str
the second arg
kwargs : str
additional args
"""
print(f"{first_arg} | {second_arg}" )
print(kwargs)
if __name__ == '__main__':
fire.Fire(cli)
Help output
❯ python .\example2.py -- --help
NAME
example2.py - Prints the 2 arguments separated by bar
SYNOPSIS
example2.py <flags>
DESCRIPTION
Prints the 2 arguments separated by bar
FLAGS
-f, --first_arg=FIRST_ARG
Default: 'left'
the first arg
-s, --second_arg=SECOND_ARG
Default: 'right'
the second arg
Additional flags are accepted.
additional args
Usage with short flags
❯ python .\example2.py -f="hello" -s="word"
left | right
{'f': 'hello', 's': 'word'}
In summary: the -f and -s arguments should be parsing to --first_arg and --second_arg but they are parsing to kwargs
- 主要语言
- Python
- 星标
- 28.2k
- 派生
- 1.5k
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
google/python-fire 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
google/python-fire#693 ·
-
Release 0.7.2? 未关闭
难度 3/5 1-2 天 新手友好度 38/100
google/python-fire#698 ·
-
难度 3/5 1-2 天 新手友好度 58/100
google/python-fire#672 · 5 条评论 ·
-
难度 4/5 3-5 天 新手友好度 45/100
google/python-fire#665 · 2 条评论 ·
-
难度 4/5 3-5 天 新手友好度 55/100
google/python-fire#659 · 1 条评论 ·
查看 google/python-fire 的全部 Issue
相似的 Issue
-
essnmx good first issue
难度 1/5 1 小时以内 新手友好度 95/100
-
难度 2/5 1-3 小时 新手友好度 65/100
syfoud/Simulated_Scepter#174 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
Giskard-AI/giskard-oss#2840 · 1 条评论 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success 未关闭area: repo bug perceived difficulty: 2
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 75/100
yeti-platform/yeti#1380 ·