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

IndexError: pop from empty list for empty tuple type annotation #7461

Closed
lycantropos opened this issue Apr 11, 2020 · 2 comments
Closed

IndexError: pop from empty list for empty tuple type annotation #7461

lycantropos opened this issue Apr 11, 2020 · 2 comments

Comments

@lycantropos
Copy link

Describe the bug
Following notation for empty tuple from this mypy issue like

from typing import Tuple

def foo() -> Tuple[()]:
	"""Sample text."""
    return ()

I get

  File "\path\to\site-packages\sphinx\domains\python.py", line 112, in unparse
    result.pop()
IndexError: pop from empty list

To Reproduce
Steps to reproduce the behavior:

  1. Write contents of snippet to module and set it to be explorable by sphinx.
  2. Install dependencies, in my docs/requirements.txt:
Sphinx>=2.0.1
sphinx-rtd-theme>=0.4.3
  1. Build docs.

Expected behavior
Docs are built and there is foo with valid type annotations.

Your project
https://github.com/lycantropos/robust/tree/1c7b74e0cc39c1843a89583b8c245f08039a3978

Environment info

  • OS: Windows 10, but also reproduces on readthedocs.
  • Python version: 3.8.0
  • Sphinx version: 3.0.1
  • Sphinx extensions: ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
@lycantropos
Copy link
Author

lycantropos commented Apr 11, 2020

Changing

result = []
for elem in node.elts:
result.extend(unparse(elem))
result.append(addnodes.desc_sig_punctuation('', ', '))
result.pop()
return result

to

            if node.elts:
                result = []
                for elem in node.elts:
                    result.extend(unparse(elem))
                    result.append(addnodes.desc_sig_punctuation('', ', '))
                result.pop()
            else:
                result = [addnodes.desc_sig_punctuation('', '('),
                          addnodes.desc_sig_punctuation('', ')')]
            return result

seems to solve the problem for me generating Tuple[()] in docs.

So it looks like empty tuples should be handled separately.

@tk0miya tk0miya added this to the 3.0.2 milestone Apr 12, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Apr 12, 2020
@tk0miya
Copy link
Member

tk0miya commented Apr 12, 2020

oops... I don't know such typing. Okay, I'll fix it soon.

tk0miya added a commit that referenced this issue Apr 13, 2020
Fix #7461: py domain: fails with IndexError for empty tuple in type annotation
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 26, 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