NiklasRosenstein / pydoc-markdown

Create Python API documentation in Markdown format.
http://niklasrosenstein.github.io/pydoc-markdown/
Other
462 stars 105 forks source link

AttributeError: 'module' object has no attribute 'signature' #21

Closed kkroening closed 7 years ago

kkroening commented 7 years ago

I'm probably doing something dumb or not understanding the instructions in the readme, but I can't seem to get the + suffix to work.

Here's an example:

# virtualenv venv
# . venv/bin/activate
# cat > foo.py << EOF
> """module comment"""
> def some_func():
>     """func comment"""
>     pass
>
> EOF

pydocmd generates output for my foo.py module:

# PYTHONPATH=. pydocmd simple foo
Building index...
Started generating documentation...
<a name="foo"></a>

# foo
module comment

But it doesn't include docs for functions in the module. If I add + on the end of the command it blows up:

# PYTHONPATH=. pydocmd simple foo+
Building index...
Started generating documentation...
Traceback (most recent call last):
  File "/Users/karlk/src/venv/bin/pydocmd", line 11, in <module>
    sys.exit(main())
  File "/Users/karlk/src/venv/lib/python2.7/site-packages/pydocmd/__main__.py", line 203, in main
    loader.load_section(section)
  File "/Users/karlk/src/venv/lib/python2.7/site-packages/pydocmd/loader.py", line 66, in load_section
    sig = get_function_signature(obj, scope if inspect.isclass(scope) else None)
  File "/Users/karlk/src/venv/lib/python2.7/site-packages/pydocmd/loader.py", line 87, in get_function_signature
    signature = inspect.signature(function)
AttributeError: 'module' object has no attribute 'signature'

The same error happens if I use generate in a pydocmd.yml file:

site_name: Welcome to pydoc-markdown
generate:
- api.md:
  - foo+
pages:
- Home: index.md << README.md

Again, works fine if I just specify foo but it doesn't include anything within the module, and adding + makes it blow up.

Is this normal? Am I doing it wrong?

NiklasRosenstein commented 7 years ago

Hi, thanks for the reporting this issue. It's definitely not normal, but a bug in Pydocmd in Python 2. inspect.signature() was added in Python 3.5. I'll have to manually generate nice docs from the argspec instead of using the signature() function.

NiklasRosenstein commented 7 years ago

Correction: inspect.signature() was added in Python 3 (only considering 3.3+), so we only have to do custom argument formatting in Python 2.

kkroening commented 7 years ago

Thanks!