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

Better error messages for fsarray slicing #150

Open
thomasballinger opened this issue Jul 24, 2020 · 0 comments
Open

Better error messages for fsarray slicing #150

thomasballinger opened this issue Jul 24, 2020 · 0 comments

Comments

@thomasballinger
Copy link
Member

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
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant