I am trying to write a type hint :rtype:
for a generator function. What is the type it returns?
For example, let's say that I have these functions that give strings:
def read_text_file(fn):
"""
Yields the lines of the text file one by one.
:param fn: Path of text file to read.
:type fn: str
:rtype: ???????????????? <======================= what goes here?
"""
with open(fn, 'rt') as text_file:
for line in text_file:
yield line
The return type is not just a string, is it some sort of iterability of strings? So I can’t just write :rtype: str
. What is the right hint?
source
share