digitaldomain / QtPyConvert

An automatic Python Qt binding transpiler to the Qt.py abstraction layer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conversion fails when there's trailing white space in an indentation block

blaisejarrett opened this issue · comments

The conversion fails with the following error when you have trailing whitespace inside of an indentation block.

2018-05-08 12:24:04 - ERROR | [QtPyConvert.run]
Line 1
from PySide import QtGui
Traceback (most recent call last):
  File "Q:\Tools\eng\bjarrett\qtpyconvert\venv\lib\site-packages\qt_py_convert\run.py", line 489, in run
    red = redbaron.RedBaron(text)
  File "Q:\Tools\eng\bjarrett\qtpyconvert\venv\lib\site-packages\redbaron\redbaron.py", line 36, in __init__
    self.node_list = base_nodes.NodeList.from_fst(baron.parse(source_code), parent=self, on_attribute="root")
  File "Q:\Tools\eng\bjarrett\qtpyconvert\venv\lib\site-packages\baron\baron.py", line 49, in parse
    tokens = tokenize(source_code, False)
  File "Q:\Tools\eng\bjarrett\qtpyconvert\venv\lib\site-packages\baron\baron.py", line 70, in tokenize
    return mark_indentation(inner_group(space_group(_tokenize(group(split(pouet)), print_function))))
  File "Q:\Tools\eng\bjarrett\qtpyconvert\venv\lib\site-packages\baron\indentation_marker.py", line 24, in mark_indentation
    return list(mark_indentation_generator(sequence))
  File "Q:\Tools\eng\bjarrett\qtpyconvert\venv\lib\site-packages\baron\indentation_marker.py", line 85, in mark_indentation_generator
    the_indentation_level_changed = get_space(current) is None or get_space(current) != indentations[-1]
  File "Q:\Tools\eng\bjarrett\qtpyconvert\venv\lib\site-packages\baron\indentation_marker.py", line 38, in get_space
    if len(node) < 3 or len(node[3]) == 0:
IndexError: tuple index out of range

The source that causes the error:

from PySide import QtGui
if True:
    app = QtGui.QApplication([]) 

Note there is a trailing space after the QApplication constructor. Here's the hex for clarity

00000000: 6672 6f6d 2050 7953 6964 6520 696d 706f  from PySide impo
00000010: 7274 2051 7447 7569 0a69 6620 5472 7565  rt QtGui.if True
00000020: 3a0a 2020 2020 6170 7020 3d20 5174 4775  :.    app = QtGu
00000030: 692e 5141 7070 6c69 6361 7469 6f6e 285b  i.QApplication([
00000040: 5d29 200a                                ]) .