@@ -104,13 +104,13 @@ def pop(self):
104104
105105 def _modified (self ):
106106 self ._lock = None
107-
108- def getlock (self ):
107+
108+ def _getlock (self ):
109109 if self ._lock is None :
110110 self ._lock = Lock ()
111111 return self ._lock
112112
113- def checklock (self , lock ):
113+ def _checklock (self , lock ):
114114 if lock is not self ._lock :
115115 raise RuntimeError ("deque mutated during iteration" )
116116
@@ -166,12 +166,12 @@ def count(self, x):
166166 result = 0
167167 block = self .leftblock
168168 index = self .leftindex
169- lock = self .getlock ()
169+ lock = self ._getlock ()
170170 for i in range (self .len ):
171171 w_item = block .data [index ]
172172 if w_item == x :
173173 result += 1
174- self .checklock (lock )
174+ self ._checklock (lock )
175175 # Advance the block/index pair
176176 index += 1
177177 if index >= BLOCKLEN :
@@ -182,6 +182,9 @@ def count(self, x):
182182 def extend (self , iterable ):
183183 """Extend the right side of the deque with elements from the iterable"""
184184 # Handle case where id(deque) == id(iterable)
185+ if self == iterable :
186+ return self .extend (list (iterable ))
187+
185188 _iter = iter (iterable )
186189 while True :
187190 try :
@@ -233,10 +236,10 @@ def remove(self, x):
233236 """Remove first occurrence of value."""
234237 block = self .leftblock
235238 index = self .leftindex
236- lock = self .getlock ()
239+ lock = self ._getlock ()
237240 for i in range (self .len ):
238241 item = block .data [index ]
239- self .checklock (lock )
242+ self ._checklock (lock )
240243 if item == x :
241244 self ._delitem (i )
242245 return
@@ -451,7 +454,7 @@ def __init__(self, dq):
451454 self .block = dq .leftblock
452455 self .index = dq .leftindex
453456 self .counter = dq .len
454- self .lock = dq .getlock ()
457+ self .lock = dq ._getlock ()
455458 assert self .index > 0
456459
457460 def __iter__ (self ):
@@ -479,11 +482,11 @@ def __next__(self):
479482
480483class _DequeRevIter (object ):
481484 def __init__ (self , dq ):
482- self .deque = dq
485+ self ._deque = dq
483486 self .block = dq .rightblock
484487 self .index = dq .rightindex
485488 self .counter = dq .len
486- self .lock = dq .getlock ()
489+ self .lock = dq ._getlock ()
487490 assert self .index > 0
488491
489492 def __iter__ (self ):
@@ -493,7 +496,7 @@ def __len__(self):
493496 return self .counter
494497
495498 def __next__ (self ):
496- if self .lock is not self .deque ._lock :
499+ if self .lock is not self ._deque ._lock :
497500 self .counter = 0
498501 raise RuntimeError ("deque mutated during iteration" )
499502 if self .counter == 0 :
0 commit comments