mis-assigned keyword arguments when two function parameters have the same name
- 主要語言
- Python
- 星號
- 28.2k
- 分支
- 1.5k
- PR 合併指標
- 30 天內沒有已合併 PR
描述
### Environment
Python 3.9.2
`fire==0.4.0`
### Example Script
I have the following example `script.py`:
```python
import fire
class Foo:
def __init__(self):
print("__init__")
def bar(self, param=0):
print(f"bar (param={param})")
return self
def baz(self, param=0):
print(f"baz (param={param})")
return self
def end(self):
return "end"
if __name__ == "__main__":
fire.Fire(Foo)
```
### Example Usages (which demonstrate a problem)
When I use the script and provide the arguments by *position*, it works fine:
```
$ python script.py bar 3 baz 5 end
__init__
bar (param=3)
baz (param=5)
end
```
But when I provide the arguments by *keyword*, the output is different and the program brings up the command-line help text for `Foo`:
```
$ python script.py bar --param=3 baz --param=5 end
__init__
bar (param=5)
baz (param=end)
```
More examples:
```
$ python script.py bar --param=3 baz 5 end
__init__
bar (param=3)
baz (param=5)
end
```
```
$ python script.py bar 3 baz --param=5 end
__init__
bar (param=5)
ERROR: Could not consume arg: 3
Usage: fire_issue_eg.py bar 3
available commands: bar | baz | end
For detailed information on this command, run:
fire_issue_eg.py bar 3 --help
```
### Thoughts
It looks like there is a problem:
- when Fire is running through two (or more) callable objects, and each object has an identically-named parameter (in the above example, `param`)
- when that parameter is provided on the command line via keyword on the 2nd(+) function called (in this example, `baz`)
貢獻指南
研究方向
Start by running the provided script.py examples through the fire.Fire(Foo) entry point and compare positional with repeated keyword arguments. Trace how chained callable invocations consume arguments; done means each --param value is assigned to its corresponding method, while the existing positional behavior and command completion remain intact.
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- cli
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100