String hinted arguments passed numerical values should not be coerced
还没有人认领这个 Issue。
评估
调研方向
issue 提供了一个位于 tp.py 的最小复现,但没有指出项目文件或测试。首先追踪 Fire 如何解析 CLI 值并应用 callable 参数的类型提示,然后找到与 string 类型提示参数相关的测试。完成标准是 1.10 和 '1.10' 都以字符串形式传入函数,并有一个回归测试覆盖这一行为。
由索引模型根据 Issue 内容生成。
描述
Observed behavior
If a callable command function defines an argument with a string hint, e.g. arg: str, and a value of 1.10 is passed to it, then it receives an argument of type float with value 1.1 which has different meaning than the passed value.
This is particularly troublesome when dealing with versions since 1.1 is much different than 1.10.
Expected behavior
Fire should not coerce the value to a type different than the type hint, regardless of its format.
Reproduction
Code
# tp.py
import fire
def main(arg: str):
print(f"Hello! {type(arg)} {arg}")
if __name__ == "__main__":
fire.Fire(main)
Execution
$ python tp.py 1.10
Hello! <class 'float'> 1.1
or
$ python tp.py '1.10'
Hello! <class 'float'> 1.1
Metadata
fire version v0.7.1
- 主要语言
- Python
- 星标
- 28.2k
- 派生
- 1.5k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
google/python-fire 的其他 Issue
-
External pager resets custom SIGINT handlers to SIG_DFL可能已有人在做 @hugosmoreira 于 14 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
google/python-fire#723 · 1 条评论 ·
-
EllipsisMiddleTruncate exceeds requested width when only the ellipsis fits可能已有人在做 @hugosmoreira 于 14 天前认领。 未关闭
难度 1/5 1-3 小时 新手友好度 88/100
google/python-fire#722 · 1 条评论 ·
-
Windows ANSI initialization uses nonexistent subprocess.STD_OUTPUT_HANDLE可能已有人在做 @Fire162 于 11 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
google/python-fire#721 · 1 条评论 ·
-
Setup docs still say `python setup.py install`, but `setup.py` was removed可能已有人在做 @GreedyC 于 18 天前认领。 未关闭
难度 1/5 1-3 小时 新手友好度 93/100
google/python-fire#718 · 1 条评论 ·
-
Calling an async command from an active event loop raises RuntimeError and leaves an unawaited coroutine可能已有人在做 @aashish254 于 20 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
google/python-fire#716 ·
查看 google/python-fire 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 67/100
bigbio/sdrf-pipelines#372 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 84/100
521xueweihan/HelloGitHub#4297 ·
-
难度 2/5 1-3 小时 新手友好度 83/100
aws-samples/sample-per-model-bedrock#822 ·
维护者通常 1 天内回复
-
area:study-data p2-high ready-for-agent type:chore
难度 2/5 1-3 小时 新手友好度 78/100
fderuiter/deruiter.dev#3706 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
awslabs/visual-asset-management-system#1234 ·
维护者通常 1 天内回复