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

lib2to3_parse assumes that the ParseError will always refer to an existing line #1

movermeyer opened this issue Jun 7, 2017 · 1 comment


Copy link

movermeyer commented Jun 7, 2017

There seems to be a case where ParseError will report the line number after the last line number, causing an IndexError in retype:

Example file (

def get_message():
    return '123'

Example stub (types/core.pyi):

def get_message() -> str: ...
$>retype --traceback
error: list index out of range
Traceback (most recent call last):
  File "", line 110, in retype_path
    retype_file(src, pyi_dir, targets, quiet=quiet, hg=hg)
  File "", line 132, in retype_file
    src_node = lib2to3_parse(src_txt)
  File "", line 161, in lib2to3_parse
    faulty_line = src_txt.splitlines()[lineno - 1]
IndexError: list index out of range

I haven't gone digging yet to see why the Driver is failing to parse this, but it seems that this should be fixed as well.

Tested using:

  • Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32
  • Python 3.6.1 (default, May 11 2017, 22:14:44) [GCC 4.9.2] on linux
Copy link
Contributor Author

movermeyer commented Jun 7, 2017

The ParseError seems to be a result of not having a newline at the end of the file.

Doesn't directly affect this bug, but will likely help you reproduce the problem.

@movermeyer movermeyer mentioned this issue Jun 8, 2017
@ambv ambv closed this as completed in #3 Jun 13, 2017
ambv pushed a commit that referenced this issue Jun 13, 2017
* - Added handling for cases where the ParseError refers to lines that don't exist in the source.
- Specifically handling the missing newline case, because it is especially difficult to diagnose.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

1 participant