如何输入提示返回函数的函数?

时间:2017-03-09 21:25:56

标签: python python-3.x type-hinting

我们说我有以下代码:

this

我的问题是如何键入提示def validator(blacklist: list=['heck', 'muffins']): def f(questionable_word: str) -> bool: return questionable_word in blacklist return f validator_british = validator(['pish']) validator_british('pish') # returns True validator_british('heck') # returns False 函数,使其指示函数被返回,特别是一个函数需要validator并返回strbool功能的签名是:

f

我应该在def f(questionable_word: str) -> bool 的{​​{1}}处放置什么?

???

1 个答案:

答案 0 :(得分:5)

typing.Callable就是你想要的:

validator(blacklist: list=['heck', 'muffins']) -> Callable[[str], bool]: