Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installing the typing backport causes autodoc errors with python 2.7.11 #2470

Closed
avirshup opened this issue Apr 19, 2016 · 3 comments
Closed

Comments

@avirshup
Copy link

avirshup commented Apr 19, 2016

Today I tried installing the (apparently new?) backport of the typing module from PyPI (I'm using Python 2.7.11). Immediately after installing the module, but before ever referencing it in my code, my documentation builds started spitting out this warning for every single function:

/path/docs/index.rst:29: WARNING: error while formatting arguments for package.Klass.biomol_summary_markdown: 'code' object has no attribute 'co_kwonlyargcount'
/path/docs/index.rst:29: WARNING: error while formatting arguments for package.Klass.calc_dipole: 'code' object has no attribute 'co_kwonlyargcount'
/path/docs/index.rst:29: WARNING: error while formatting arguments for package.Klass.calc_electronic_state: 'code' object has no attribute 'co_kwonlyargcount'

The HTML documentation does get built, but all the arguments are missing from all functions. The problem goes away if you run pip uninstall typing

Steps to reproduce:
Using python 2.7:
pip install typing

Then run make html for any project. It should produce many errors like the ones shown above, and the produced documentation should be missing all function arguments.

If I had to guess, by installing the typing module, I somehow tricked autodoc into thinking that I'm using 3.5?

Workaround
pip uninstall typing

@jmchilton
Copy link

jmchilton commented Apr 25, 2016

I've discovered this also - my work around I think will be to install an explicitly older version of typing typing==3.5.0.1. There is something fishy with the python2 source directory of the 3.5.1 branch/tag of typing - but I cannot find any particular diff that is the problem - master branch looks find and 3.5.1 doesn't.

Never mind, that doesn't seem to fix the problem.

@tk0miya
Copy link
Member

tk0miya commented May 21, 2016

In my short investigation:

It seems the typing package does not support python 2.x environment.
At least, typing.get_type_hints() does not work. I got following stacktrace from Sphinx:

Traceback (most recent call last):
  File "/Users/tkomiya/work/sphinx/sphinx/cmdline.py", line 244, in main
    app.build(opts.force_all, filenames)
  File "/Users/tkomiya/work/sphinx/sphinx/application.py", line 294, in build
    self.builder.build_update()
  File "/Users/tkomiya/work/sphinx/sphinx/builders/__init__.py", line 251, in build_update
    'out of date' % len(to_build))
  File "/Users/tkomiya/work/sphinx/sphinx/builders/__init__.py", line 265, in build
    self.doctreedir, self.app))
  File "/Users/tkomiya/work/sphinx/sphinx/environment.py", line 548, in update
    self._read_serial(docnames, app)
  File "/Users/tkomiya/work/sphinx/sphinx/environment.py", line 568, in _read_serial
    self.read_doc(docname, app)
  File "/Users/tkomiya/work/sphinx/sphinx/environment.py", line 721, in read_doc
    pub.publish()
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/core.py", line 217, in publish
    self.settings)
  File "/Users/tkomiya/work/sphinx/sphinx/io.py", line 49, in read
    self.parse()
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/readers/__init__.py", line 78, in parse
    self.parser.parse(self.input, document)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/__init__.py", line 172, in parse
    self.statemachine.run(inputlines, document, inliner=self.inliner)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 170, in run
    input_source=document['source'])
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/statemachine.py", line 239, in run
    context, state, transitions)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/statemachine.py", line 460, in check_line
    return method(match, context, next_state)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2726, in underline
    self.section(title, source, style, lineno - 1, messages)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 327, in section
    self.new_subsection(title, lineno, messages)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 395, in new_subsection
    node=section_node, match_titles=True)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 282, in nested_parse
    node=node, match_titles=match_titles)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/statemachine.py", line 239, in run
    context, state, transitions)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/statemachine.py", line 460, in check_line
    return method(match, context, next_state)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2299, in explicit_markup
    nodelist, blank_finish = self.explicit_construct(match)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2311, in explicit_construct
    return method(self, expmatch)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2054, in directive
    directive_class, match, type_name, option_presets)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2103, in run_directive
    result = directive_instance.run()
  File "/Users/tkomiya/work/sphinx/sphinx/ext/autodoc.py", line 1623, in run
    nested_parse_with_titles(self.state, self.result, node)
  File "/Users/tkomiya/work/sphinx/sphinx/util/nodes.py", line 177, in nested_parse_with_titles
    return state.nested_parse(content, 0, node, match_titles=1)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 282, in nested_parse
    node=node, match_titles=match_titles)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/statemachine.py", line 239, in run
    context, state, transitions)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/statemachine.py", line 460, in check_line
    return method(match, context, next_state)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2301, in explicit_markup
    self.explicit_list(blank_finish)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2331, in explicit_list
    match_titles=self.state_machine.match_titles)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 319, in nested_list_parse
    node=node, match_titles=match_titles)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/statemachine.py", line 239, in run
    context, state, transitions)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/statemachine.py", line 460, in check_line
    return method(match, context, next_state)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2604, in explicit_markup
    nodelist, blank_finish = self.explicit_construct(match)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2311, in explicit_construct
    return method(self, expmatch)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2054, in directive
    directive_class, match, type_name, option_presets)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2103, in run_directive
    result = directive_instance.run()
  File "/Users/tkomiya/work/sphinx/sphinx/ext/autosummary/__init__.py", line 210, in run
    items = self.get_items(names)
  File "/Users/tkomiya/work/sphinx/sphinx/ext/autosummary/__init__.py", line 297, in get_items
    sig = documenter.format_signature()
  File "/Users/tkomiya/work/sphinx/sphinx/ext/autodoc.py", line 1135, in format_signature
    return Documenter.format_signature(self)
  File "/Users/tkomiya/work/sphinx/sphinx/ext/autodoc.py", line 591, in format_signature
    args = self.format_args()
  File "/Users/tkomiya/work/sphinx/sphinx/ext/autodoc.py", line 1188, in format_args
    args = formatargspec(self.object, *argspec)
  File "/Users/tkomiya/work/sphinx/sphinx/ext/autodoc.py", line 333, in formatargspec
    if typing and hasattr(function, '__code__') else {})
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/typing.py", line 1157, in get_type_hints
    defaults = _get_defaults(obj)
  File "/Users/tkomiya/work/tmp/lib/python2.7/site-packages/typing.py", line 1114, in _get_defaults
    kw_count = code.co_kwonlyargcount
AttributeError: 'code' object has no attribute 'co_kwonlyargcount'

@tk0miya
Copy link
Member

tk0miya commented May 21, 2016

Fixed at 20b3da5.
Sphinx ignores the typing package on py2.x.

Thank you for reporting!

@tk0miya tk0miya closed this as completed May 21, 2016
@tk0miya tk0miya added this to the 1.4.2 milestone May 21, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants