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

TypeError: 'type' object is not iterable #8157

Closed
mauro835 opened this issue Aug 28, 2020 · 2 comments
Closed

TypeError: 'type' object is not iterable #8157

mauro835 opened this issue Aug 28, 2020 · 2 comments

Comments

@mauro835
Copy link

mauro835 commented Aug 28, 2020

Hi All,
this is the first time I try to create a documentation using Sphinx.
venv is a virutal environment created with miniconda.
Using the Miniconda3 prompt, I activated the environment and tried
to create the documentation.
As suggested in the error, please find below the error log.
Thanks a lot for your help!
PS: for privacy, I hide my absolute path calling it PATH.

 Sphinx version: 3.2.1
 Python version: 3.8.5 (CPython)
 Docutils version: 0.16 release
 Jinja2 version: 2.11.2
 Last messages:
   Running Sphinx v3.2.1
   building [mo]: targets for 0 po files that are out of date
   building [html]: targets for 22 source files that are out of date
   updating environment:
   [new config]
   22 added, 0 changed, 0 removed
   reading sources... [  4%] eopack
 Loaded extensions:
   sphinx.ext.mathjax (3.2.1) from PATH\venv\lib\site-packages\sphinx\ext\mathjax.py
   sphinxcontrib.applehelp (1.0.2) from PATH\venv\lib\site-packages\sphinxcontrib\applehelp\__init__.py
   sphinxcontrib.devhelp (1.0.2) from PATH\venv\lib\site-packages\sphinxcontrib\devhelp\__init__.py
   sphinxcontrib.htmlhelp (1.0.3) from PATH\venv\lib\site-packages\sphinxcontrib\htmlhelp\__init__.py
   sphinxcontrib.serializinghtml (1.1.4) from PATH\venv\lib\site-packages\sphinxcontrib\serializinghtml\__init__.py
   sphinxcontrib.qthelp (1.0.3) from PATH\venv\lib\site-packages\sphinxcontrib\qthelp\__init__.py
   alabaster (0.7.12) from PATH\venv\lib\site-packages\alabaster\__init__.py
   sphinx.ext.autodoc.type_comment (3.2.1) from PATH\venv\lib\site-packages\sphinx\ext\autodoc\type_comment.py
   sphinx.ext.autodoc (3.2.1) from PATH\venv\lib\site-packages\sphinx\ext\autodoc\__init__.py
   sphinxcontrib.napoleon (0.7) from PATH\venv\lib\site-packages\sphinxcontrib\napoleon\__init__.py
Traceback (most recent call last):
  File "PATH\venv\lib\site-packages\sphinx\cmd\build.py", line 280, in build_main
    app.build(args.force_all, filenames)
  File "PATH\venv\lib\site-packages\sphinx\application.py", line 348, in build
    self.builder.build_update()
  File "PATH\venv\lib\site-packages\sphinx\builders\__init__.py", line 297, in build_update
    self.build(to_build,
  File "PATH\venv\lib\site-packages\sphinx\builders\__init__.py", line 311, in build
    updated_docnames = set(self.read())
  File "PATH\venv\lib\site-packages\sphinx\builders\__init__.py", line 418, in read
    self._read_serial(docnames)
  File "PATH\venv\lib\site-packages\sphinx\builders\__init__.py", line 439, in _read_serial
    self.read_doc(docname)
  File "PATH\venv\lib\site-packages\sphinx\builders\__init__.py", line 479, in read_doc
    doctree = read_doc(self.app, self.env, self.env.doc2path(docname))
  File "PATH\venv\lib\site-packages\sphinx\io.py", line 223, in read_doc
    pub.publish()
  File "PATH\venv\lib\site-packages\docutils\core.py", line 217, in publish
    self.document = self.reader.read(self.source, self.parser,
  File "PATH\venv\lib\site-packages\sphinx\io.py", line 128, in read
    self.parse()
  File "PATH\venv\lib\site-packages\docutils\readers\__init__.py", line 77, in parse
    self.parser.parse(self.input, document)
  File "PATH\venv\lib\site-packages\sphinx\parsers.py", line 102, in parse
    self.statemachine.run(inputlines, document, inliner=self.inliner)
  File "PATH\venv\lib\site-packages\docutils\parsers\rst\states.py", line 170, in run
    results = StateMachineWS.run(self, input_lines, input_offset,
  File "PATH\venv\lib\site-packages\docutils\statemachine.py", line 241, in run
    context, next_state, result = self.check_line(
  File "PATH\venv\lib\site-packages\docutils\statemachine.py", line 459, in check_line
    return method(match, context, next_state)
  File "PATH\venv\lib\site-packages\docutils\parsers\rst\states.py", line 2769, in underline
    self.section(title, source, style, lineno - 1, messages)
  File "PATH\venv\lib\site-packages\docutils\parsers\rst\states.py", line 327, in section
    self.new_subsection(title, lineno, messages)
  File "PATH\venv\lib\site-packages\docutils\parsers\rst\states.py", line 393, in new_subsection
    newabsoffset = self.nested_parse(
  File "PATH\venv\lib\site-packages\docutils\parsers\rst\states.py", line 281, in nested_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "PATH\venv\lib\site-packages\docutils\parsers\rst\states.py", line 196, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "PATH\venv\lib\site-packages\docutils\statemachine.py", line 241, in run
    context, next_state, result = self.check_line(
  File "PATH\venv\lib\site-packages\docutils\statemachine.py", line 459, in check_line
    return method(match, context, next_state)
  File "PATH\venv\lib\site-packages\docutils\parsers\rst\states.py", line 2769, in underline
    self.section(title, source, style, lineno - 1, messages)
  File "PATH\venv\lib\site-packages\docutils\parsers\rst\states.py", line 327, in section
    self.new_subsection(title, lineno, messages)
  File "PATH\venv\lib\site-packages\docutils\parsers\rst\states.py", line 393, in new_subsection
    newabsoffset = self.nested_parse(
  File "PATH\venv\lib\site-packages\docutils\parsers\rst\states.py", line 281, in nested_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "PATH\venv\lib\site-packages\docutils\parsers\rst\states.py", line 196, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "PATH\venv\lib\site-packages\docutils\statemachine.py", line 241, in run
    context, next_state, result = self.check_line(
  File "PATH\venv\lib\site-packages\docutils\statemachine.py", line 459, in check_line
    return method(match, context, next_state)
  File "PATH\venv\lib\site-packages\docutils\parsers\rst\states.py", line 2342, in explicit_markup
    nodelist, blank_finish = self.explicit_construct(match)
  File "PATH\venv\lib\site-packages\docutils\parsers\rst\states.py", line 2354, in explicit_construct
    return method(self, expmatch)
  File "PATH\venv\lib\site-packages\docutils\parsers\rst\states.py", line 2096, in directive
    return self.run_directive(
  File "PATH\venv\lib\site-packages\docutils\parsers\rst\states.py", line 2146, in run_directive
    result = directive_instance.run()
  File "PATH\venv\lib\site-packages\sphinx\ext\autodoc\directive.py", line 146, in run
    documenter.generate(more_content=self.content)
  File "PATH\venv\lib\site-packages\sphinx\ext\autodoc\__init__.py", line 894, in generate
    self.document_members(all_members)
  File "PATH\venv\lib\site-packages\sphinx\ext\autodoc\__init__.py", line 775, in document_members
    documenter.generate(
  File "PATH\venv\lib\site-packages\sphinx\ext\autodoc\__init__.py", line 1568, in generate
    return super().generate(more_content=more_content,
  File "PATH\venv\lib\site-packages\sphinx\ext\autodoc\__init__.py", line 894, in generate
    self.document_members(all_members)
  File "PATH\venv\lib\site-packages\sphinx\ext\autodoc\__init__.py", line 1559, in document_members
    super().document_members(all_members)
  File "PATH\venv\lib\site-packages\sphinx\ext\autodoc\__init__.py", line 775, in document_members
    documenter.generate(
  File "PATH\venv\lib\site-packages\sphinx\ext\autodoc\__init__.py", line 884, in generate
    self.add_directive_header(sig)
  File "PATH\venv\lib\site-packages\sphinx\ext\autodoc\__init__.py", line 2003, in add_directive_header
    objrepr = stringify_typehint(annotations.get(self.objpath[-1]))
  File "PATH\venv\lib\site-packages\sphinx\util\typing.py", line 80, in stringify
    return _stringify_py37(annotation)
  File "PATH\venv\lib\site-packages\sphinx\util\typing.py", line 116, in _stringify_py37
    args = ', '.join(stringify(a) for a in annotation.__args__)
  File "PATH\venv\lib\site-packages\sphinx\util\typing.py", line 116, in <genexpr>
    args = ', '.join(stringify(a) for a in annotation.__args__)
  File "PATH\venv\lib\site-packages\sphinx\util\typing.py", line 80, in stringify
    return _stringify_py37(annotation)
  File "PATH\venv\lib\site-packages\sphinx\util\typing.py", line 124, in _stringify_py37
    elif all(is_system_TypeVar(a) for a in annotation.__args__):
TypeError: 'type' object is not iterable
@tk0miya
Copy link
Member

tk0miya commented Sep 5, 2020

I suppose this error was raised when autodoc could not process some kind of type annotation. So I need to know what kind of python code was documented. Could you share your project? Or could you make a minimal reproducible example?

@mauro835
Copy link
Author

mauro835 commented Sep 8, 2020

Thanks for your reply. Unfortunately, I cannot share the whole project but thanks to your hint, I understood the problem is related to the package nptyping. I get the error when I do something like:

from nptyping import NDArray
def funct(a: NDArray[float]) -> float

I hope this helps.
If it's not enough, I would try to make a more detailed example, please let me know.

tk0miya added a commit to tk0miya/sphinx that referenced this issue Oct 2, 2020
… invalid __args__

Typically, the __args__ attribute of type annotations is a tuple
containing arguments for the types (ex. The __args__ of `List[int]` is
`(int,)`).  But some kind of types has non tuple __args__ attribute.
For example, `nptyping.NDArray` is one of them.

This fixes the TypeError when the invalid __args__ attribute found.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Oct 2, 2020
… invalid __args__

Typically, the __args__ attribute of type annotations is a tuple
containing arguments for the types (ex. The __args__ of `List[int]` is
`(int,)`).  But some kind of types has non tuple __args__ attribute.
For example, `nptyping.NDArray` is one of them.

This fixes the TypeError when the invalid __args__ attribute found.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Oct 4, 2020
… invalid __args__

Typically, the __args__ attribute of type annotations is a tuple
containing arguments for the types (ex. The __args__ of `List[int]` is
`(int,)`).  But some kind of types has non tuple __args__ attribute.
For example, `nptyping.NDArray` is one of them.

This fixes the TypeError when the invalid __args__ attribute found.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Oct 4, 2020
… invalid __args__

Typically, the __args__ attribute of type annotations is a tuple
containing arguments for the types (ex. The __args__ of `List[int]` is
`(int,)`).  But some kind of types has non tuple __args__ attribute.
For example, `nptyping.NDArray` is one of them.

This fixes the TypeError when the invalid __args__ attribute found.
@tk0miya tk0miya closed this as completed in 9a0a0f9 Oct 4, 2020
tk0miya added a commit that referenced this issue Oct 4, 2020
Fix #8157: autodoc: TypeError is raised when annotation has invalid __args__
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 19, 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

2 participants