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__ importannotations
78

89

910
classNumberWords:
@@ -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
returnself
2627

27-
def__next__(self): # this makes the class an Iterator
28+
def__next__(self)->str: # this makes the class an Iterator
2829
ifself.start>self.stoporself.start>len(self._WORD_MAP):
2930
raiseStopIteration
3031
current=self.start

0 commit comments

Comments
(0)