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

autodoc.type_comments throw IndexError #7146

Closed
gpotter2 opened this issue Feb 13, 2020 · 1 comment
Closed

autodoc.type_comments throw IndexError #7146

gpotter2 opened this issue Feb 13, 2020 · 1 comment

Comments

@gpotter2
Copy link
Contributor

gpotter2 commented Feb 13, 2020

Describe the bug
Since 2.4.0, we get a failure on our test suites:

Warning, treated as error:
1116error while formatting arguments for scapy.contrib.http2.HPackHdrTable.parse_txt_hdrs: list index out of range

I mocked sphinx to display the stack trace:

Exception occurred:
2914  File "/home/travis/build/secdev/scapy/.tox/docs/lib/python3.8/site-packages/Sphinx-2.4.2.dev20200213-py3.8.egg/sphinx/ext/autodoc/type_comment.py", line 62, in update_annotations_using_type_comments
2915    annotation = ast_unparse(function.argtypes[i])  # type: ignore

Here's what the function looks like:
https://github.com/secdev/scapy/blob/0dd974e46b3678f02e422dacafc507f32cacde89/scapy/contrib/http2.py#L2636

The issue happens whenever there is a mismatch between the amount of arguments and the amount of type hints comments. This happens when using the (...)

This triggers it:

def pony(a,
         b,  # type: str
         c=None  # type: Optional[str]
         ):
    # type: (...) -> str
    return b + (c or "")

This is an issue when using functions within class. You don't put a type hint for self (https://mypy.readthedocs.io/en/stable/cheat_sheet.html#classes)

Full travis logs

https://travis-ci.com/secdev/scapy/jobs/286619573
Backup:
https://pastebin.com/raw/vxhT1cGq

To Reproduce

Steps to reproduce the behavior:

$ git clone https://github.com/gpotter2/issues-sphinx.git
$ cd issues-sphinx
$ make html

Your project
https://github.com/secdev/scapy

Environment info

  • OS: linux
  • Python version: 3.8.1
  • Sphinx version: 2.4.1
  • Sphinx extensions: sphinx.ext.autodoc

Thanks for the time.

@gpotter2
Copy link
Contributor Author

gpotter2 commented Feb 13, 2020

Another note: type_comments is enabled by default on 2.4.0+ even if typehints is disabled. This has no effect on the final output but creates bugs such as this one on existing code

@tk0miya tk0miya added this to the 2.4.2 milestone Feb 14, 2020
tk0miya added a commit that referenced this issue Feb 16, 2020
Fix #7146: support (...) in type hint comments (V2)
@tk0miya tk0miya closed this as completed Feb 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 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