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

key in btree should ignore OverflowError #140

Closed
jamadden opened this issue Apr 6, 2020 · 0 comments
Closed

key in btree should ignore OverflowError #140

jamadden opened this issue Apr 6, 2020 · 0 comments
Assignees

Comments

@jamadden
Copy link
Member

jamadden commented Apr 6, 2020

Currently, key in btree ignores TypeError, so this all works:

>>> import BTrees
>>> bt = BTrees.family32.II.BTree()
>>> 'abc' in bt
False
>>> bt.get('abc') is None
True

But if the key is outside the range allowed, it fails:

>>> x = 2 ** 64
>>> x in bt
OverflowError: Python int too large to convert to C long
>>>  bt.get(x)
OverflowError: Python int too large to convert to C long

For consistency, the OverflowError should be ignored in those cases too. (This would happen automatically if it was a TypeError instead of an OverflowError.) The pure-Python implementation already handles this (…by raising a TypeError, I think).

Also weird and should not raise (works in pure-Python):

>>> bt.has_key(1)
0
>>> bt.has_key('abc')
KeyError: 'abc'
>>> bt.has_key(x)
OverflowError: Python int too large to convert to C long

Confirmed this to be an issue back to 4.6. The changes in 4.3.2 were not sufficient for the overflow case.

@jamadden jamadden self-assigned this Apr 6, 2020
jamadden added a commit that referenced this issue Apr 7, 2020
Fix #140 by turning OverflowError into TypeError.
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