@@ -104,13 +104,13 @@ def pop(self):
104
104
105
105
def _modified (self ):
106
106
self ._lock = None
107
-
108
- def getlock (self ):
107
+
108
+ def _getlock (self ):
109
109
if self ._lock is None :
110
110
self ._lock = Lock ()
111
111
return self ._lock
112
112
113
- def checklock (self , lock ):
113
+ def _checklock (self , lock ):
114
114
if lock is not self ._lock :
115
115
raise RuntimeError ("deque mutated during iteration" )
116
116
@@ -166,12 +166,12 @@ def count(self, x):
166
166
result = 0
167
167
block = self .leftblock
168
168
index = self .leftindex
169
- lock = self .getlock ()
169
+ lock = self ._getlock ()
170
170
for i in range (self .len ):
171
171
w_item = block .data [index ]
172
172
if w_item == x :
173
173
result += 1
174
- self .checklock (lock )
174
+ self ._checklock (lock )
175
175
# Advance the block/index pair
176
176
index += 1
177
177
if index >= BLOCKLEN :
@@ -182,6 +182,9 @@ def count(self, x):
182
182
def extend (self , iterable ):
183
183
"""Extend the right side of the deque with elements from the iterable"""
184
184
# Handle case where id(deque) == id(iterable)
185
+ if self == iterable :
186
+ return self .extend (list (iterable ))
187
+
185
188
_iter = iter (iterable )
186
189
while True :
187
190
try :
@@ -233,10 +236,10 @@ def remove(self, x):
233
236
"""Remove first occurrence of value."""
234
237
block = self .leftblock
235
238
index = self .leftindex
236
- lock = self .getlock ()
239
+ lock = self ._getlock ()
237
240
for i in range (self .len ):
238
241
item = block .data [index ]
239
- self .checklock (lock )
242
+ self ._checklock (lock )
240
243
if item == x :
241
244
self ._delitem (i )
242
245
return
@@ -451,7 +454,7 @@ def __init__(self, dq):
451
454
self .block = dq .leftblock
452
455
self .index = dq .leftindex
453
456
self .counter = dq .len
454
- self .lock = dq .getlock ()
457
+ self .lock = dq ._getlock ()
455
458
assert self .index > 0
456
459
457
460
def __iter__ (self ):
@@ -479,11 +482,11 @@ def __next__(self):
479
482
480
483
class _DequeRevIter (object ):
481
484
def __init__ (self , dq ):
482
- self .deque = dq
485
+ self ._deque = dq
483
486
self .block = dq .rightblock
484
487
self .index = dq .rightindex
485
488
self .counter = dq .len
486
- self .lock = dq .getlock ()
489
+ self .lock = dq ._getlock ()
487
490
assert self .index > 0
488
491
489
492
def __iter__ (self ):
@@ -493,7 +496,7 @@ def __len__(self):
493
496
return self .counter
494
497
495
498
def __next__ (self ):
496
- if self .lock is not self .deque ._lock :
499
+ if self .lock is not self ._deque ._lock :
497
500
self .counter = 0
498
501
raise RuntimeError ("deque mutated during iteration" )
499
502
if self .counter == 0 :
0 commit comments