Allow destructive ops during son iteration
and let python handle (identical to iter on list)
This commit is contained in:
parent
01b499850c
commit
26f3f40fc9
@ -120,13 +120,7 @@ class SON(dict):
|
||||
# efficient.
|
||||
# second level definitions support higher levels
|
||||
def __iter__(self):
|
||||
"""
|
||||
Cannot remove nor add keys while iterating
|
||||
"""
|
||||
key_len = len(self.__keys)
|
||||
for k in self.__keys:
|
||||
if len(self.__keys) != key_len:
|
||||
raise RuntimeError("son changed length during iteration")
|
||||
yield k
|
||||
|
||||
def has_key(self, key):
|
||||
|
||||
@ -163,11 +163,6 @@ class TestSON(unittest.TestCase):
|
||||
test_son = SON([(1, 100), (2, 200), (3, 300)])
|
||||
for ele in test_son:
|
||||
self.assertEqual(ele * 100, test_son[ele])
|
||||
# test failure case
|
||||
def break_iter():
|
||||
for ele in test_son:
|
||||
del test_son[ele]
|
||||
self.assertRaises(RuntimeError, break_iter)
|
||||
|
||||
def test_contains_has(self):
|
||||
"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user