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.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。