我想弄清楚什麼放在我的類型註釋在這個函數的頂部。Python類型暗示與curses
我有以下簡單的例子:
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'>
。這看起來好像不能和Type提示一起工作,因爲它有一個空格。
預計的結果將是
編輯:這裏的文檔不正確。WindowObject
列於
the documentation。我在curses模塊本身中找不到WindowObject的路徑。
如何用精確的類型註釋編寫main?
只是不。 'WindowObject'是一個文檔錯誤;窗口對象類型的名稱是未記錄的,並且可能會更改,並且我認爲窗口對象類型甚至不可用作爲模塊屬性。 – user2357112
Absolutamente right @ user2357112,type()方法總是告訴類型對象,不管它是什麼 –
儘管這是一個奇怪的情況。我沒有看到一個類型(),其中有一個空格。打字庫如何處理這些?我並不是說我需要這樣做,但這是一個奇怪的例子。 – Technoloft