Skip to content

Commit d752949

Browse files
committed
Added type hints to iterator pattern
1 parent ade29d6 commit d752949

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

patterns/behavioral/iterator_alt.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*TL;DR
55
Traverses a container and accesses the container's elements.
66
"""
7+
from __future__ import annotations
78

89

910
class NumberWords:
@@ -17,14 +18,14 @@ class NumberWords:
1718
"five",
1819
)
1920

20-
def __init__(self, start, stop):
21+
def __init__(self, start: int, stop: int) -> None:
2122
self.start = start
2223
self.stop = stop
2324

24-
def __iter__(self): # this makes the class an Iterable
25+
def __iter__(self) -> NumberWords: # this makes the class an Iterable
2526
return self
2627

27-
def __next__(self): # this makes the class an Iterator
28+
def __next__(self) -> str: # this makes the class an Iterator
2829
if self.start > self.stop or self.start > len(self._WORD_MAP):
2930
raise StopIteration
3031
current = self.start

0 commit comments

Comments
 (0)