summaryrefslogtreecommitdiff
path: root/sphinx/ext/napoleon/iterators.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-07-03 01:44:13 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-07-04 01:10:15 +0900
commitf0579fcd4a6a5380b896e8baac346a7b98dd70ca (patch)
treee2f24db2ebd916c6c31f89e8763d67976a2642db /sphinx/ext/napoleon/iterators.py
parent0a98664866053312b1aef539f98c656fb5a7e65f (diff)
downloadsphinx-git-f0579fcd4a6a5380b896e8baac346a7b98dd70ca.tar.gz
Migrate to py3 style type annotation: sphinx.ext.napoleon.iterators
Diffstat (limited to 'sphinx/ext/napoleon/iterators.py')
-rw-r--r--sphinx/ext/napoleon/iterators.py32
1 files changed, 10 insertions, 22 deletions
diff --git a/sphinx/ext/napoleon/iterators.py b/sphinx/ext/napoleon/iterators.py
index d9de4fb80..3aa728e44 100644
--- a/sphinx/ext/napoleon/iterators.py
+++ b/sphinx/ext/napoleon/iterators.py
@@ -11,10 +11,7 @@
"""
import collections
-
-if False:
- # For type annotation
- from typing import Any, Iterable # NOQA
+from typing import Any, Iterable
class peek_iter:
@@ -50,8 +47,7 @@ class peek_iter:
be set to a new object instance: ``object()``.
"""
- def __init__(self, *args):
- # type: (Any) -> None
+ def __init__(self, *args) -> None:
"""__init__(o, sentinel=None)"""
self._iterable = iter(*args) # type: Iterable
self._cache = collections.deque() # type: collections.deque
@@ -60,18 +56,15 @@ class peek_iter:
else:
self.sentinel = object()
- def __iter__(self):
- # type: () -> peek_iter
+ def __iter__(self) -> "peek_iter":
return self
- def __next__(self, n=None):
- # type: (int) -> Any
+ def __next__(self, n: int = None) -> Any:
# note: prevent 2to3 to transform self.next() in next(self) which
# causes an infinite loop !
return getattr(self, 'next')(n)
- def _fillcache(self, n):
- # type: (int) -> None
+ def _fillcache(self, n: int) -> None:
"""Cache `n` items. If `n` is 0 or None, then 1 item is cached."""
if not n:
n = 1
@@ -82,8 +75,7 @@ class peek_iter:
while len(self._cache) < n:
self._cache.append(self.sentinel)
- def has_next(self):
- # type: () -> bool
+ def has_next(self) -> bool:
"""Determine if iterator is exhausted.
Returns
@@ -98,8 +90,7 @@ class peek_iter:
"""
return self.peek() != self.sentinel
- def next(self, n=None):
- # type: (int) -> Any
+ def next(self, n: int = None) -> Any:
"""Get the next item or `n` items of the iterator.
Parameters
@@ -134,8 +125,7 @@ class peek_iter:
result = [self._cache.popleft() for i in range(n)]
return result
- def peek(self, n=None):
- # type: (int) -> Any
+ def peek(self, n: int = None) -> Any:
"""Preview the next item or `n` items of the iterator.
The iterator is not advanced when peek is called.
@@ -218,8 +208,7 @@ class modify_iter(peek_iter):
"whitespace."
"""
- def __init__(self, *args, **kwargs):
- # type: (Any, Any) -> None
+ def __init__(self, *args, **kwargs) -> None:
"""__init__(o, sentinel=None, modifier=lambda x: x)"""
if 'modifier' in kwargs:
self.modifier = kwargs['modifier']
@@ -233,8 +222,7 @@ class modify_iter(peek_iter):
'modifier must be callable')
super().__init__(*args)
- def _fillcache(self, n):
- # type: (int) -> None
+ def _fillcache(self, n: int) -> None:
"""Cache `n` modified items. If `n` is 0 or None, 1 item is cached.
Each item returned by the iterator is passed through the