bpython / curtsies

Curses-like terminal wrapper with a display based on compositing 2d arrays of text.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Better error messages for fsarray slicing

thomasballinger opened this issue · comments

Lots of assignments could have better error messages.

>>> arr = fsarray([cyan('hello'), 'there!'])
>>> arr.dumb_display()
hello
there!
>>> arr[1:2] = 'goodbye'
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    arr[1:2] = 'goodbye'
  File "/Users/tomb/src/curtsies/curtsies/formatstringarray.py", line 147, in __setitem__
    raise ValueError('if slice is 2D, value must be 2D')
ValueError: if slice is 2D, value must be 2D
>>> arr[1:2, 3:4] = 'x'
>>> arr[1:2, 3:4] = ['x']
>>> arr[1:3, 3:4] = ['x']
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    arr[1:3, 3:4] = ['x']
  File "/Users/tomb/src/curtsies/curtsies/formatstringarray.py", line 169, in __setitem__
    raise ValueError('row dimensions do not match: %r, %r' % (len(value), rowslice))
ValueError: row dimensions do not match: 1, slice(1, 3, None)
>>> arr[1:3, 3:4] = 'x'
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    arr[1:3, 3:4] = 'x'
  File "/Users/tomb/src/curtsies/curtsies/formatstringarray.py", line 169, in __setitem__
    raise ValueError('row dimensions do not match: %r, %r' % (len(value), rowslice))
ValueError: row dimensions do not match: 1, slice(1, 3, None)
>>> arr[1:3, :] = ['abcdefg', 'hijklmn']
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    arr[1:3, :] = ['abcdefg', 'hijklmn']
  File "/Users/tomb/src/curtsies/curtsies/formatstringarray.py", line 171, in __setitem__
    [fs.setslice_with_length(colslice.start, colslice.stop, v, self.num_columns) for fs, v in zip(self.rows[rowslice], value)] +
  File "/Users/tomb/src/curtsies/curtsies/formatstringarray.py", line 171, in <listcomp>
    [fs.setslice_with_length(colslice.start, colslice.stop, v, self.num_columns) for fs, v in zip(self.rows[rowslice], value)] +
  File "/Users/tomb/src/curtsies/curtsies/formatstring.py", line 334, in setslice_with_length
    assert len(result) <= length
AssertionError
>>>