python-fire
python-fire copied to clipboard
--help not working with classes
I cannot get --help to work with classes. I've read the (oldish) "current state" in #364 but it did not help.
Using the example from the documentation
import fire
class Building(object):
def __init__(self, name, stories=1):
self.name = name
self.stories = stories
def climb_stairs(self, stairs_per_story=10):
for story in range(self.stories):
for stair in range(1, stairs_per_story):
yield stair
yield 'Phew!'
yield 'Done!'
if __name__ == '__main__':
fire.Fire(Building)
I get an error when I run the command suggested in the documentation:
$ python exmaple.py --name="Sherrerd Hall"
Traceback (most recent call last):
File "example.py", line 17, in <module>
fire.Fire(Building)
File "XXX/lib/python3.12/site-packages/fire/core.py", line 161, in Fire
_PrintResult(
File "XXX/lib/python3.12/site-packages/fire/core.py", line 272, in _PrintResult
help_text = helptext.HelpText(
^^^^^^^^^^^^^^^^^^
File "XXX/lib/python3.12/site-packages/fire/helptext.py", line 61, in HelpText
info = inspectutils.Info(component)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "XXX/lib/python3.12/site-packages/fire/inspectutils.py", line 259, in Info
inspector = oinspect.Inspector()
^^^^^^^^^^^^^^^^^^^^
TypeError: Inspector.__init__() missing 1 required keyword-only argument: 'theme_name'
If I run
python exmaple.py --name="Sherrerd Hall" -- help
I ge the same error; I was expecting to see the methods here. Even if I modified the call to any of
python example.py --name="Sherrerd Hall" --stories=3 -- --help
python example.py --name="Sherrerd Hall" --stories=3 climb_stairs -- --help
python example.py --name="Sherrerd Hall" --stories=3 climb_stairs 2 -- --help
I always get the same error as above.
If I call the method it works
$ python example.py --name="Sherrerd Hall" --stories=3 climb_stairs 2
1
Phew!
1
Phew!
1
Phew!
Done!
using python 3.12.3 fire 0.7.0
Same issue here.
python: 3.12.9 fire: 0.7.0
@kakila It looks like the root issue is that I have ipython version greater than v9.0.0 in my environment.
The Inspector initialization part introduced a breaking change.
Downgrading the ipython version can restore functionality as a workaround.
Related PR: !588
TypeError: Inspector.init() missing 1 required keyword-only argument: 'theme_name'
This should be fixed in v0.7.1 👍. Thanks for reporting.