Nat*_*ord 3 python type-hinting python-3.x
假设我有以下代码:
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
Run Code Online (Sandbox Code Playgroud)
我的问题是我该如何键入提示该validator
函数,以使其指示返回了一个函数,特别是需要a str
并返回a 的函数bool
?该f
函数的签名是:
def f(questionable_word: str) -> bool
Run Code Online (Sandbox Code Playgroud)
我放什么???
地方validator
?
validator(blacklist: list=['heck', 'muffins']) -> ???:
Run Code Online (Sandbox Code Playgroud)
typing.Callable
是您想要的:
validator(blacklist: list=['heck', 'muffins']) -> Callable[[str], bool]:
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
219 次 |
最近记录: |