Skip to content

Commit f105dce

Browse files
committed
Remove Python 2 compatibility SON methods
Python 3.0 [removed `dict.has_key()`](https://docs.python.org/3/whatsnew/3.0.html#views-and-iterators-instead-of-lists:~:text=Removed%2E%20dict%2Ehas%5Fkey%28%29) and [the `dict.iter*()` methods](https://docs.python.org/3/whatsnew/3.0.html#views-and-iterators-instead-of-lists:~:text=Also%2C%20the%20dict%2Eiterkeys%28%29%2C%20dict%2Eiteritems%28%29%20and%20dict%2Eitervalues%28%29%20methods%20are%20no%20longer%20supported). fcedc51 removed `SON.iteritems()` to align with its removal in Python 3. This commit cleans up by removing the remaining compatibility methods: `has_key()`, `iterkeys()`, and `itervalues()`.
1 parent 668bd82 commit f105dce

File tree

2 files changed

+1
-14
lines changed

2 files changed

+1
-14
lines changed

bson/son.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,6 @@ def copy(self) -> SON[_Key, _Value]:
9898
def __iter__(self) -> Iterator[_Key]:
9999
yield from self.__keys
100100

101-
def has_key(self, key: _Key) -> bool:
102-
return key in self.__keys
103-
104-
def iterkeys(self) -> Iterator[_Key]:
105-
return self.__iter__()
106-
107-
# fourth level uses definitions from lower levels
108-
def itervalues(self) -> Iterator[_Value]:
109-
for _, v in self.items():
110-
yield v
111-
112101
def values(self) -> list[_Value]: # type: ignore[override]
113102
return [v for _, v in self.items()]
114103

test/test_son.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,12 @@ def test_iteration(self):
144144
for ele in test_son:
145145
self.assertEqual(ele * 100, test_son[ele])
146146

147-
def test_contains_has(self):
147+
def test_contains(self):
148148
"""has_key and __contains__"""
149149
test_son = SON([(1, 100), (2, 200), (3, 300)])
150150
self.assertIn(1, test_son)
151151
self.assertIn(2, test_son, "in failed")
152152
self.assertNotIn(22, test_son, "in succeeded when it shouldn't")
153-
self.assertTrue(test_son.has_key(2), "has_key failed")
154-
self.assertFalse(test_son.has_key(22), "has_key succeeded when it shouldn't")
155153

156154
def test_clears(self):
157155
"""Test clear()"""

0 commit comments

Comments
 (0)