46
46
47
47
48
48
class 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
+ """
50
54
51
55
sentinel = object ()
52
56
@@ -57,6 +61,12 @@ def get(self, n: int) -> Any:
57
61
"""
58
62
return self [n ] if n < len (self ) else self .sentinel
59
63
64
+ def next (self ) -> Any :
65
+ if self :
66
+ return super ().popleft ()
67
+ else :
68
+ raise StopIteration
69
+
60
70
61
71
def _convert_type_spec (_type : str , translations : Dict [str , str ] = {}) -> str :
62
72
"""Convert type specification to reference in reST."""
@@ -240,7 +250,7 @@ def _consume_indented_block(self, indent: int = 1) -> List[str]:
240
250
line = self ._lines .get (0 )
241
251
while (not self ._is_section_break () and
242
252
(not line or self ._is_indented (line , indent ))):
243
- lines .append (self ._lines .popleft ())
253
+ lines .append (self ._lines .next ())
244
254
line = self ._lines .get (0 )
245
255
return lines
246
256
@@ -249,20 +259,20 @@ def _consume_contiguous(self) -> List[str]:
249
259
while (self ._lines and
250
260
self ._lines .get (0 ) and
251
261
not self ._is_section_header ()):
252
- lines .append (self ._lines .popleft ())
262
+ lines .append (self ._lines .next ())
253
263
return lines
254
264
255
265
def _consume_empty (self ) -> List [str ]:
256
266
lines = []
257
267
line = self ._lines .get (0 )
258
268
while self ._lines and not line :
259
- lines .append (self ._lines .popleft ())
269
+ lines .append (self ._lines .next ())
260
270
line = self ._lines .get (0 )
261
271
return lines
262
272
263
273
def _consume_field (self , parse_type : bool = True , prefer_type : bool = False
264
274
) -> Tuple [str , str , List [str ]]:
265
- line = self ._lines .popleft ()
275
+ line = self ._lines .next ()
266
276
267
277
before , colon , after = self ._partition_field_on_colon (line )
268
278
_name , _type , _desc = before , '' , after
@@ -300,7 +310,7 @@ def _consume_fields(self, parse_type: bool = True, prefer_type: bool = False,
300
310
return fields
301
311
302
312
def _consume_inline_attribute (self ) -> Tuple [str , List [str ]]:
303
- line = self ._lines .popleft ()
313
+ line = self ._lines .next ()
304
314
_type , colon , _desc = self ._partition_field_on_colon (line )
305
315
if not colon or not _desc :
306
316
_type , _desc = _desc , _type
@@ -338,7 +348,7 @@ def _consume_usage_section(self) -> List[str]:
338
348
return lines
339
349
340
350
def _consume_section_header (self ) -> str :
341
- section = self ._lines .popleft ()
351
+ section = self ._lines .next ()
342
352
stripped_section = section .strip (':' )
343
353
if stripped_section .lower () in self ._sections :
344
354
section = stripped_section
@@ -347,14 +357,14 @@ def _consume_section_header(self) -> str:
347
357
def _consume_to_end (self ) -> List [str ]:
348
358
lines = []
349
359
while self ._lines :
350
- lines .append (self ._lines .popleft ())
360
+ lines .append (self ._lines .next ())
351
361
return lines
352
362
353
363
def _consume_to_next_section (self ) -> List [str ]:
354
364
self ._consume_empty ()
355
365
lines = []
356
366
while not self ._is_section_break ():
357
- lines .append (self ._lines .popleft ())
367
+ lines .append (self ._lines .next ())
358
368
return lines + self ._consume_empty ()
359
369
360
370
def _dedent (self , lines : List [str ], full : bool = False ) -> List [str ]:
@@ -1170,7 +1180,7 @@ def _escape_args_and_kwargs(self, name: str) -> str:
1170
1180
1171
1181
def _consume_field (self , parse_type : bool = True , prefer_type : bool = False
1172
1182
) -> Tuple [str , str , List [str ]]:
1173
- line = self ._lines .popleft ()
1183
+ line = self ._lines .next ()
1174
1184
if parse_type :
1175
1185
_name , _ , _type = self ._partition_field_on_colon (line )
1176
1186
else :
@@ -1201,10 +1211,10 @@ def _consume_returns_section(self, preprocess_types: bool = False
1201
1211
return self ._consume_fields (prefer_type = True )
1202
1212
1203
1213
def _consume_section_header (self ) -> str :
1204
- section = self ._lines .popleft ()
1214
+ section = self ._lines .next ()
1205
1215
if not _directive_regex .match (section ):
1206
1216
# Consume the header underline
1207
- self ._lines .popleft ()
1217
+ self ._lines .next ()
1208
1218
return section
1209
1219
1210
1220
def _is_section_break (self ) -> bool :
0 commit comments