【发布时间】:2017-10-14 18:18:25
【问题描述】:
我正在尝试找出在此函数顶部的类型注释中放入什么内容。
我有以下简单的例子:
import curses
def main(stdscr):
stdscr.clear()
stdscr.addstr(2, 0, "What is the type of stdscr?")
stdscr.addstr(5, 0, "It is: {}".format(type(stdscr)))
stdscr.refresh()
stdscr.getkey()
curses.wrapper(main)
这将返回<type '_curses.curses window'>。这似乎不适用于类型提示,因为它有一个空格。 预期结果将是the documentation 中列出的 编辑:这里的文档不正确。WindowObject。我在 curses 模块本身中找不到 WindowObject 的路径。
如何编写带有准确类型注释的 main?
【问题讨论】:
-
别这样。
WindowObject是文档错误;窗口对象类型的名称没有记录并且可能会更改,而且我认为窗口对象类型甚至不能作为模块属性使用。 -
绝对正确@user2357112,type() 方法总是告诉类型对象,无论如何
-
这是一个奇怪的案例。我还没有看到里面有空格的 type() 。 Typing 库如何处理这些?我并不是说我需要这样做,但这是一个奇怪的案例。
标签: python python-3.5 python-3.6 type-hinting python-curses