1
我的IDE(PyCharm)未能自動完成以下事項:打字內置地圖功能
from typing import List, TypeVar
T = TypeVar('T')
def listify(x: T) -> List[T]:
return [x]
str_list: List[str] = ['a', 'b']
listified = map(listify, str_list)
listified[0].<TAB> # autocomplete fail, IDE fails to recognize this is a List
這是我的IDE有問題,或者是typing
與map
不兼容?
不管答案是什麼,我試圖通過包裝map
修復:再次
from typing import Callable, Iterable, List, TypeVar
T = TypeVar('T')
U = TypeVar('U')
def listify(x: T) -> List[T]:
return [x]
def univariate_map(func: Callable[[T], U], x: Iterable[T]) -> Iterable[U]:
return map(func, x)
str_list: List[str] = ['a', 'b']
listified = univariate_map(listify, str_list)
listified[0].<TAB> # still fails to autocomplete
,這是一個問題,我的IDE,或者是我的typing
模塊的預期不正確的?
哎呀,這很愚蠢。對不起,我應該嘗試運行一些實際的代碼,而不是嘗試自動完成。謝謝! – dshin
@abccd ok!你真的困惑我:) – MSeifert