google / google/python-fire

Support __call__ and __getattr__ on module

未關閉
#328 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
28.2k
分支
1.5k
PR 合併指標
30 天內沒有已合併 PR

描述

Given code like this:

```python
def hardcoded():
# ...

def __getattr__(name):
# ...

def __call__(*args):
# ...

if __name__ == '__main__':
fire.Fire(run)
```

I would like fire to call `hardcoded` function when `hardcoded` is specified on command line. Otherwise, I would like it to fall back on `__getattr__` or `__call__`. I don't care which one, but I think both can be supported at the same time with `__getattr__` being tried first.

Current workaround is to use helper object with `__call__` method on it, but that hides all global functions in the module, so forwarding methods have to be added to the helper object.

貢獻指南

開啟貢獻指南

研究方向

Start at the fire.Fire(run) entry point shown in the issue and trace how Python modules and their attributes are resolved. Check how hardcoded functions are selected, then determine where module-level __getattr__ or __call__ could be considered as fallbacks. Done means command-line names still invoke hardcoded functions and otherwise use the requested module fallback behavior.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
cli
Issue 類型
功能
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。