【发布时间】:2017-09-25 07:41:43
【问题描述】:
我正在尝试为生成器函数编写:rtype: 类型提示。它返回的类型是什么?
例如,假设我有这个产生字符串的函数:
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
返回类型不仅仅是一个字符串,它是某种可迭代的字符串?所以我不能只写:rtype: str。正确的提示是什么?
【问题讨论】:
-
返回带有字符串的生成器
-
看起来你不是要求类型提示,而是
:rtype:的文档字符串插入 -
人们甚至没有阅读问题就标记为重复。叹息……
-
@Wood 再看一遍...
-
@Jean-FrançoisCorbett 另一个问题要求类型注释。这个请求为
:rtype:插入文档字符串。它们是不同的东西。
标签: python python-2.7 generator yield type-hinting