Skip to content

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

Description

@movermeyer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions