Comments (5)
You can certainly inspect the Fire function with Fire!
To inspect a function without calling it, and '-- --help' to your command. Without that, the function will get called. And as you noticed, when Fire is called with no arguments, it spits out all your locals and globals.
from python-fire.
Why does a callable class not get called?
Compare the following:
import fire
from __future__ import print_function
lamb = lambda: print(123)
class CallableClass:
def __call__(self):
print(123)
def function():
print(123)
def arity(x, y):
print(123)
fire.Fire(lamb)
fire.Fire(CallableClass) # note `inspect.getsourcefile` throws when this is used in the interpreter
fire.Fire(CallableClass())
fire.Fire(function)
fire.Fire(arity)
fire.Fire()
Unrelated rant: I personally feel the zero-arity function
shouldn't get called even when --help
is used. I realize a function might have a help
argument but I'd rather break that argument name than the expectation of every single command line app with no arguments (I commonly use --help
by itself as I'm sure many others do based on the included warning). Sorry I'm kind of using this issue as a feedback post at this point.
from python-fire.
Sorry I'm kind of using this issue as a feedback post at this point.
Not a problem.
I personally feel the zero-arity function shouldn't get called even when --help is used.
Yes, largely I agree. Currently I'm leaning toward having --help behave the same as '-- --help' (e.g. preventing the final fn/class from being called/instantiated) except in the case where the fn accepts a help argument (either explicitly or via **kwargs). I want to as much as possible allow Fire to work on any Python component at all.
Why does a callable class not get called?
This is because we currently only look for argspecs on classes and routines, but not on other objects (in your example it's the instantiated object that is callable, not the class itself).
I am certainly open to changing this behavior. It's a nontrivial change and could introduce ambiguous commands, and so will require careful thought.
fire.Fire(CallableClass) # note
inspect.getsourcefile
throws when this is used in the interpreter
Good catch. We should fix this.
from python-fire.
The getsourcefile issue is resolved now. 1239bdd
from python-fire.
from python-fire.
Related Issues (20)
- [bug] short flags/arguments does not work with `**kwargs` HOT 1
- Add Docker Image for easier setup
- [Question] Even if no type hints is supplied, would `python-fire` accept stub files? HOT 1
- Fire needs to include features like in ArgParse
- Get execution context HOT 2
- Strings args do not need to be parsed. HOT 3
- Warning Deprecation: Legacy 'setup.py'
- [feature request] support multiple dialects for boolean parameters HOT 3
- [feature request] Exclude function (kw)args from synopsis, arguments and flags in help output
- guide sample code is entered incorrectly HOT 2
- Version flag alongside other commands HOT 3
- Remove test requirement on mock HOT 4
- Is it possible to pass arg via code and kwargs by cli (sys.argv) ? HOT 1
- cli for function created on the fly HOT 1
- ERROR: Could not consume arg: >> HOT 1
- AttributeError: 'module' object has no attribute 'PY34' HOT 1
- How to set the number of args at least one? HOT 1
- Python 2.7 no longer available in GitHub Actions by default HOT 1
- Unexpected printing (+paging) when using inspect HOT 3
- Cannot parse list of strings containing `is` HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-fire.