Issues

Issue #1385 resolved

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

Choongmin 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():
    """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
    self.parse()
  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 (3)

  1. Log in to comment