google / google/python-fire

Support __call__ and __getattr__ on module

オープン
#328 コメント 2 件 リアクション 0 件 担当者 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 を短くまとめたダイジェスト。