我们说我有以下代码:
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
并返回str
? bool
功能的签名是:
f
我应该在def f(questionable_word: str) -> bool
的{{1}}处放置什么?
???
答案 0 :(得分:5)
typing.Callable
就是你想要的:
validator(blacklist: list=['heck', 'muffins']) -> Callable[[str], bool]: