小编ByA*_*enT的帖子

"void"函数中的NoReturn与None - 在Python 3.6中键入注释

Python 3.6支持类型注释,如:

def foo() -> int:
    return 42
Run Code Online (Sandbox Code Playgroud)

但是当函数没有返回任何内容时,预期会使用什么?PEP484示例主要None用作返回类型,但也有包中的NoReturn类型typing.

所以,问题是什么是更好的使用和什么被认为是最佳实践:

def foo() -> None:
    #do smth
Run Code Online (Sandbox Code Playgroud)

要么

from typing import NoReturn

def foo() -> NoReturn:
    #do smth
Run Code Online (Sandbox Code Playgroud)

python annotations typing type-hinting python-3.6

7
推荐指数
1
解决办法
1493
查看次数

标签 统计

annotations ×1

python ×1

python-3.6 ×1

type-hinting ×1

typing ×1