4646
4747
4848class Deque (collections .deque ):
49- """A subclass of deque with an additional `.Deque.get` method."""
49+ """
50+ A subclass of deque that mimics ``pockets.iterators.modify_iter``.
51+
52+ The `.Deque.get` and `.Deque.next` methods are added.
53+ """
5054
5155 sentinel = object ()
5256
@@ -57,6 +61,12 @@ def get(self, n: int) -> Any:
5761 """
5862 return self [n ] if n < len (self ) else self .sentinel
5963
64+ def next (self ) -> Any :
65+ if self :
66+ return super ().popleft ()
67+ else :
68+ raise StopIteration
69+
6070
6171def _convert_type_spec (_type : str , translations : Dict [str , str ] = {}) -> str :
6272 """Convert type specification to reference in reST."""
@@ -240,7 +250,7 @@ def _consume_indented_block(self, indent: int = 1) -> List[str]:
240250 line = self ._lines .get (0 )
241251 while (not self ._is_section_break () and
242252 (not line or self ._is_indented (line , indent ))):
243- lines .append (self ._lines .popleft ())
253+ lines .append (self ._lines .next ())
244254 line = self ._lines .get (0 )
245255 return lines
246256
@@ -249,20 +259,20 @@ def _consume_contiguous(self) -> List[str]:
249259 while (self ._lines and
250260 self ._lines .get (0 ) and
251261 not self ._is_section_header ()):
252- lines .append (self ._lines .popleft ())
262+ lines .append (self ._lines .next ())
253263 return lines
254264
255265 def _consume_empty (self ) -> List [str ]:
256266 lines = []
257267 line = self ._lines .get (0 )
258268 while self ._lines and not line :
259- lines .append (self ._lines .popleft ())
269+ lines .append (self ._lines .next ())
260270 line = self ._lines .get (0 )
261271 return lines
262272
263273 def _consume_field (self , parse_type : bool = True , prefer_type : bool = False
264274 ) -> Tuple [str , str , List [str ]]:
265- line = self ._lines .popleft ()
275+ line = self ._lines .next ()
266276
267277 before , colon , after = self ._partition_field_on_colon (line )
268278 _name , _type , _desc = before , '' , after
@@ -300,7 +310,7 @@ def _consume_fields(self, parse_type: bool = True, prefer_type: bool = False,
300310 return fields
301311
302312 def _consume_inline_attribute (self ) -> Tuple [str , List [str ]]:
303- line = self ._lines .popleft ()
313+ line = self ._lines .next ()
304314 _type , colon , _desc = self ._partition_field_on_colon (line )
305315 if not colon or not _desc :
306316 _type , _desc = _desc , _type
@@ -338,7 +348,7 @@ def _consume_usage_section(self) -> List[str]:
338348 return lines
339349
340350 def _consume_section_header (self ) -> str :
341- section = self ._lines .popleft ()
351+ section = self ._lines .next ()
342352 stripped_section = section .strip (':' )
343353 if stripped_section .lower () in self ._sections :
344354 section = stripped_section
@@ -347,14 +357,14 @@ def _consume_section_header(self) -> str:
347357 def _consume_to_end (self ) -> List [str ]:
348358 lines = []
349359 while self ._lines :
350- lines .append (self ._lines .popleft ())
360+ lines .append (self ._lines .next ())
351361 return lines
352362
353363 def _consume_to_next_section (self ) -> List [str ]:
354364 self ._consume_empty ()
355365 lines = []
356366 while not self ._is_section_break ():
357- lines .append (self ._lines .popleft ())
367+ lines .append (self ._lines .next ())
358368 return lines + self ._consume_empty ()
359369
360370 def _dedent (self , lines : List [str ], full : bool = False ) -> List [str ]:
@@ -1170,7 +1180,7 @@ def _escape_args_and_kwargs(self, name: str) -> str:
11701180
11711181 def _consume_field (self , parse_type : bool = True , prefer_type : bool = False
11721182 ) -> Tuple [str , str , List [str ]]:
1173- line = self ._lines .popleft ()
1183+ line = self ._lines .next ()
11741184 if parse_type :
11751185 _name , _ , _type = self ._partition_field_on_colon (line )
11761186 else :
@@ -1201,10 +1211,10 @@ def _consume_returns_section(self, preprocess_types: bool = False
12011211 return self ._consume_fields (prefer_type = True )
12021212
12031213 def _consume_section_header (self ) -> str :
1204- section = self ._lines .popleft ()
1214+ section = self ._lines .next ()
12051215 if not _directive_regex .match (section ):
12061216 # Consume the header underline
1207- self ._lines .popleft ()
1217+ self ._lines .next ()
12081218 return section
12091219
12101220 def _is_section_break (self ) -> bool :
0 commit comments