Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BTrees
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
BTrees
Commits
5b3421f8
Commit
5b3421f8
authored
Dec 22, 2016
by
Jason Madden
Committed by
GitHub
Dec 22, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #56 from zopefoundation/issue51
Python/C OO consistency
parents
1fb38674
a7b7ea11
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
9 deletions
+56
-9
BTrees/_base.py
BTrees/_base.py
+1
-1
BTrees/tests/test_OOBTree.py
BTrees/tests/test_OOBTree.py
+43
-4
CHANGES.rst
CHANGES.rst
+12
-4
No files found.
BTrees/_base.py
View file @
5b3421f8
...
...
@@ -111,7 +111,7 @@ class _BucketBase(_Base):
while
low
<
high
:
i
=
(
low
+
high
)
//
2
k
=
keys
[
i
]
if
k
==
key
:
if
k
is
key
or
k
==
key
:
return
i
if
k
<
key
:
low
=
i
+
1
...
...
BTrees/tests/test_OOBTree.py
View file @
5b3421f8
...
...
@@ -161,12 +161,12 @@ class OOBTreeTest(BTreeTests, unittest.TestCase):
self
.
assertRaises
(
KeyError
,
t
.
__getitem__
,
C
())
self
.
assertFalse
(
C
()
in
t
)
# Check that a None key can be deleted in Python 2.
# This doesn't work on Python 3 because None is unorderable,
# so the tree can't be searched. But None also can't be inserted,
# and we don't support migrating Python 2 databases to Python 3.
@
_skip_under_Py3k
def
testDeleteNoneKey
(
self
):
# Check that a None key can be deleted in Python 2.
# This doesn't work on Python 3 because None is unorderable,
# so the tree can't be searched. But None also can't be inserted,
# and we don't support migrating Python 2 databases to Python 3.
t
=
self
.
_makeOne
()
bucket_state
=
((
None
,
42
),)
tree_state
=
((
bucket_state
,),)
...
...
@@ -175,6 +175,45 @@ class OOBTreeTest(BTreeTests, unittest.TestCase):
self
.
assertEqual
(
t
[
None
],
42
)
del
t
[
None
]
def
testUnpickleNoneKey
(
self
):
# All versions (py2 and py3, C and Python) can unpickle
# data that looks like this: {None: 42}, even though None
# is unorderable..
# This pickle was captured in BTree/ZODB3 3.10.7
data
=
b'ccopy_reg
\
n
__newobj__
\
n
p0
\
n
(cBTrees.OOBTree
\
n
OOBTree
\
n
p1
\
n
tp2
\
n
Rp3
\
n
((((NI42
\
n
tp4
\
n
tp5
\
n
tp6
\
n
tp7
\
n
b.'
import
pickle
t
=
pickle
.
loads
(
data
)
keys
=
list
(
t
)
self
.
assertEqual
([
None
],
keys
)
def
testIdentityTrumpsBrokenComparison
(
self
):
# Identical keys always match, even if their comparison is
# broken. See https://github.com/zopefoundation/BTrees/issues/50
from
functools
import
total_ordering
@
total_ordering
class
Bad
(
object
):
def
__eq__
(
self
,
other
):
return
False
def
__cmp__
(
self
,
other
):
return
1
def
__lt__
(
self
,
other
):
return
False
t
=
self
.
_makeOne
()
bad_key
=
Bad
()
t
[
bad_key
]
=
42
self
.
assertIn
(
bad_key
,
t
)
self
.
assertEqual
(
list
(
t
),
[
bad_key
])
del
t
[
bad_key
]
self
.
assertNotIn
(
bad_key
,
t
)
self
.
assertEqual
(
list
(
t
),
[])
class
OOBTreePyTest
(
OOBTreeTest
):
#
...
...
CHANGES.rst
View file @
5b3421f8
...
...
@@ -6,10 +6,18 @@
- Make the CPython implementation consistent with the pure-Python
implementation and only check object keys for default comparison
when setting keys. In Python 2 this makes it possible to remove
keys that were added using a less restrictive version of BTrees.
(In Python 3 keys that are unorderable still cannot be removed.)
See: https://github.com/zopefoundation/BTrees/issues/53
when setting keys. In Python 2 this makes it possible to remove keys
that were added using a less restrictive version of BTrees. (In
Python 3 keys that are unorderable still cannot be removed.)
Likewise, all versions can unpickle trees that already had such
keys. See: https://github.com/zopefoundation/BTrees/issues/53 and
https://github.com/zopefoundation/BTrees/issues/51
- Make the Python implementation consistent with the CPython
implementation and check object key identity before checking
equality and performing comparisons. This can allow fixing trees
that have keys that now have broken comparison functions. See
https://github.com/zopefoundation/BTrees/issues/50
- Make the CPython implementation consistent with the pure-Python
implementation and no longer raise ``TypeError`` for an object key
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment