google / python-fire

Python Fire is a library for automatically generating command line interfaces (CLIs) from absolutely any Python object.
Other
27.06k stars 1.45k forks source link

Error after an upgrade to the last version #183

Closed Krazybug closed 5 years ago

Krazybug commented 5 years ago

Hello, After an upgrade to the current version of Fire, I got the following error on a script i ran without any change.

>python myscript.py --help
INFO: Showing help with the command 'myscript.py -- --help'.

Traceback (most recent call last):
  File "myscript.py", line 733, in <module>
    fire.Fire()
  File ".../lib/python3.7/site-packages/fire/core.py", line 158, in Fire
    result, trace=component_trace, verbose=component_trace.verbose)
  File ".../lib/python3.7/site-packages/fire/helptext.py", line 78, in HelpText
    actions_grouped_by_kind)
  File ".../lib/python3.7/site-packages/fire/helptext.py", line 230, in _UsageDetailsSections
    sections.append(_MakeUsageDetailsSection(commands))
  File ".../lib/python3.7/site-packages/fire/helptext.py", line 415, in _MakeUsageDetailsSection
    info = inspectutils.Info(member)
  File ".../lib/python3.7/site-packages/fire/inspectutils.py", line 211, in Info
    info['docstring_info'] = docstrings.parse(info['docstring'])
  File ".../cali2/lib/python3.7/site-packages/fire/docstrings.py", line 180, in parse
    _consume_line(line_info, state)
  File ".../lib/python3.7/site-packages/fire/docstrings.py", line 413, in _consume_line
    _update_section_state(line_info, state)
  File ".../python3.7/site-packages/fire/docstrings.py", line 525, in _update_section_state
    google_section_permitted = _google_section_permitted(line_info, state)
  File ".../lib/python3.7/site-packages/fire/docstrings.py", line 582, in _google_section_permitted
    or line_info.indentation < state.section.line1_indentation)
TypeError: '<' not supported between instances of 'int' and 'NoneType'

It Seems that a object is compared in docstring.py

FYI: I don't have any docstring (""") in my script and this other snippet diplays correct help message but the error is still displayed after the help message:

import fire

def test():
    print("OK")

if __name__ == "__main__":
    fire.Fire()

Note also that when I reinstall fire, this snippet works perfectly (doc is displayed without an error following) as the help of every subcommands of my script. It's only when i run python myscript.py --help that it's displayed the first time and after on each script i ran. It's sounds like something persistent changed in my env.

My version of python is 3.7.3. I'm using virtualenv and pip and here are my dependencies:

>pip freeze
beautifulsoup4==4.7.1
bs4==0.0.1
certifi==2019.3.9
chardet==3.0.4
fire==0.2.0
gevent==1.4.0
greenlet==0.4.15
humanize==0.5.1
idna==2.8
iso639==0.1.4
langid==1.1.6
lxml==4.3.4
numpy==1.16.3
requests==2.22.0
six==1.12.0
soupsieve==1.9.1
termcolor==1.1.0
urllib3==1.25.3
Krazybug commented 5 years ago

By dichotomy, I got it and you should be able to reproduce it:

Run python myscript.py --help with this code:

import fire
import requests
# from requests.adapters import HTTPAdapter

def my_subcommand(dir= '.', server=''):
    pass

if __name__ == "__main__":
    fire.Fire()

Uncomment the 3rd line and you should get the error !

dbieber commented 5 years ago

Thanks for the report. Looks like a bug in our docstring parser. I'll take a closer look.

Krazybug commented 5 years ago

Congratulations it's already fixed! Awaiting the next release how can I modify my code to avoid this message ?

dbieber commented 5 years ago

We'll do the release this week.

In the mean time, setting HTTPAdapter.__doc__ = '' should unblock you.

dbieber commented 5 years ago

Release is live. pip install -U fire to upgrade. Thanks again for the bug report!

Krazybug commented 5 years ago

Thanks to you for the hard and efficient work !