google / google/python-fire

Support __call__ and __getattr__ on module

Open
#328 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
28.2k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.