You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to deal with classmethod or staticmethod? #113
import fire
class Calculator(object):
"""A simple calculator class."""
base = 10
def __init__(self, x):
self.x = x
def double(self, number):
return self.x * number
@classmethod
def test(cls, number):
return cls.base * number
if __name__ == '__main__':
fire.Fire(Calculator)
=== a.py =====================================
If I want to call func test, I need to do like this: python a.py --x 3 test 5
So how to call classmethod or staticmethod without initialize the class (python a.py test 5 )?
Thanks for raising this to my attention.
At the moment you do need to initialize the class, so python a.py --x 3 test 5 will work while python a.py test 5 will not.
We should either fix or document this.
Thanks for the fix! Yes, the approach looks good to me. It's a little non-standard for Fire because it updates component twice in the same iteration of the main loop, but that may be OK. One place where we'll have to be careful is if the command ends on an access of a class method or static method, without calling it (e.g. because the user wants help about a class method). We'll have to make sure we handle this case properly.
Let's add some thorough tests and check this in.
The linter is rather picky (currently complaining about line-too-long errors.) You can see test and lint output in travis by clicking the red x (or green checkmark) next to your commit / pull request.
I have (finally) responded to your pull request.
If you're up for making the requested changes, go for it :). If you've since moved on to other parts of the internet and I don't hear back from you, no worries - my apologies for the slow turnaround.
This is now fixed (unintentionally, actually!) It was fixed by the commit that improved support for callable objects (0e1dfe5), allowing users to both call or access members of a callable object. It fixes this issue because it also allows users to both instantiate a class or access its members (such as a classmethod or staticmethod.)
The fix will be available in this coming Friday's release.
Activity
dbieber commentedon Jan 30, 2018
Thanks for raising this to my attention.
At the moment you do need to initialize the class, so
python a.py --x 3 test 5will work whilepython a.py test 5will not.We should either fix or document this.
rozuur commentedon Oct 3, 2018
can I fix this?
rozuur commentedon Oct 6, 2018
@dbieber I have fixed the issue, let me know if the approach is correct so that I can add test cases to it.
dbieber commentedon Oct 6, 2018
Thanks for the fix! Yes, the approach looks good to me. It's a little non-standard for Fire because it updates component twice in the same iteration of the main loop, but that may be OK. One place where we'll have to be careful is if the command ends on an access of a class method or static method, without calling it (e.g. because the user wants help about a class method). We'll have to make sure we handle this case properly.
Let's add some thorough tests and check this in.
The linter is rather picky (currently complaining about line-too-long errors.) You can see test and lint output in travis by clicking the red x (or green checkmark) next to your commit / pull request.
rozuur commentedon Oct 7, 2018
Will add test cases, fix lint errors and update the pull requests.
dbieber commentedon Oct 31, 2018
Apologies for the delay on this, I'll keep you posted as I get round to reviewing this.
dbieber commentedon Jan 3, 2019
I have (finally) responded to your pull request.
If you're up for making the requested changes, go for it :). If you've since moved on to other parts of the internet and I don't hear back from you, no worries - my apologies for the slow turnaround.
dbieber commentedon Jul 24, 2019
This is now fixed (unintentionally, actually!) It was fixed by the commit that improved support for callable objects (0e1dfe5), allowing users to both call or access members of a callable object. It fixes this issue because it also allows users to both instantiate a class or access its members (such as a classmethod or staticmethod.)
The fix will be available in this coming Friday's release.