Code Monkey home page Code Monkey logo

Comments (5)

dbieber avatar dbieber commented on May 17, 2024

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.

ubershmekel avatar ubershmekel commented on May 17, 2024

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.

dbieber avatar dbieber commented on May 17, 2024

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.

dbieber avatar dbieber commented on May 17, 2024

The getsourcefile issue is resolved now. 1239bdd

from python-fire.

1445drewran avatar 1445drewran commented on May 17, 2024

from python-fire.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.