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

unsupported types in getitem must raise either TypeError or ValueError, not AssertionError #1095

Open
gdementen opened this issue Feb 9, 2024 · 0 comments

Comments

@gdementen
Copy link
Contributor

Unsure which though.

>>> arr = ndtest((2, 3))
>>> arr[object()]
AssertionError: <object object at 0x000001F2737241B0> (<class 'object'>) is not scalar
>>> arr[None]
AssertionError: None (<class 'NoneType'>) is not scalar
>>> class A:
...     def __eq__(self):
...         return False
>>> a = A()
>>> arr[a]
AssertionError: <larray_editor.api.A object at 0x000001F2746AF190> (<class 'larray_editor.api.A'>) is not scalar

Compare this with dict:

>>> d = {}
>>> d[object()]
KeyError: <object object at 0x000001F26E653520>
>>> d[None]
KeyError: None
>>> d[a]
TypeError: unhashable type: 'A'

I also wonder why we raise ValueError when a key is not found instead of KeyError or at least some kind of LookupError? I remember looking at StackOverflow for this, but I don't remember the reasoning anymore.

>>> arr['b4']
ValueError: 'b4' is not a valid label for any axis:
 a [2]: 'a0' 'a1'
 b [3]: 'b0' 'b1' 'b2'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant