google / google/python-fire

Support __call__ and __getattr__ on module

Offen
#328 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
28.2k
Forks
1.5k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.