sphinx.pycode.ModuleAnalyzer fails with print function in Python 2

Choongmin Lee avatarChoongmin Lee created an issue

Using print function by importing it from future raises PycodeError.

To reproduce this bug, save the following as foo.py:

from __future__ import print_function
import sys

def foo():
    print("Bar", file=sys.stderr)

Then run:

>>> from sphinx.pycode import ModuleAnalyzer
>>> a = ModuleAnalyzer.for_module('foo')
>>> a.find_attr_docs()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/choongmin/.virtualenvs/audiodiff/lib/python2.7/site-packages/sphinx/pycode/__init__.py", line 266, in find_attr_docs
  File "/Users/choongmin/.virtualenvs/audiodiff/lib/python2.7/site-packages/sphinx/pycode/__init__.py", line 260, in parse
    raise PycodeError('parsing failed', err)
sphinx.errors.PycodeError: parsing failed (exception was: ParseError("bad input: type=22, value=u'=', context=('', (6, 21))",))

This bug causes module data members to disappear and autodoc_member_order = 'by source' to be ignored.

Comments (2)

  1. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.