Support __call__ and __getattr__ on module
- 主要語言
- 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