我正在尝试弄清楚要在该函数顶部的类型注释中添加什么内容。
我有以下简单的例子:
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'>
。这似乎不适用于类型提示,因为它里面有一个空格。 文档中列出。我在 curses 模块本身中找不到 WindowObject 的路径。 编辑:此处的文档不正确。
,但 Windows 对象尚未添加。您可以在here和here自行检查Python 3“curses”存根。 目前,存根默认输入
WindowObject
为:
curses.wrapper
...这又相当于:
def wrapper(func, *args, **kwds): ...
所以,这意味着除了
def wrapper(func: Callable[..., Any], *args: Any, **kwds: Any): ...
之外,目前确实没有合适的类型可以分配给
main
函数的参数。也就是说,如果您愿意,您也许可以贡献一些存根来自己完成
Any
模块!看起来
Window 对象并没有那么复杂,并且应该能够相对简单地输入。 主要的复杂性可能是确定“Window”对象到底应该从哪里导入,如果它不存在于curses模块本身中的话。您可能希望将“Windows”对象粘贴在
curses
模块本身中,就像
typing
和 typing.re.Pattern
一样。
typing.re.Match
对类型进行注释
curses.window