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

Closed
movermeyer opened this Issue Jun 7, 2017 · 1 comment

Comments

Projects
None yet
1 participant
@movermeyer
Contributor

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 (core.py):

def get_message():
    return '123'

Example stub (types/core.pyi):

def get_message() -> str: ...
$>retype --traceback core.py
error: core.py: list index out of range
Traceback (most recent call last):
  File "retype.py", line 110, in retype_path
    retype_file(src, pyi_dir, targets, quiet=quiet, hg=hg)
  File "retype.py", line 132, in retype_file
    src_node = lib2to3_parse(src_txt)
  File "retype.py", 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
@movermeyer

This comment has been minimized.

Contributor

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 referenced this issue Jun 8, 2017

Merged

Fix for #1 #3

@ambv ambv closed this in #3 Jun 13, 2017

ambv added a commit that referenced this issue Jun 13, 2017

Fix for #1 (#3)
* - 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