__init__ 的正确类型注释

Correct Type annotation for __init__

python 中 __init__ 函数的正确类型注释是什么?

class MyClass:
    ...

以下哪项更有意义?

def __init__(self):
    # type: (None) -> None

def __init__(self):
    # type: (MyClass) -> MyClass

def __init__(self):
    # type: (None) -> MyClass

因为我们通常会实例化为 myclass = MyClass(),但是 __init__ 函数本身没有 return 值。

self作为注释给出时应从注释中省略,__init__()应标记为-> None。这些都在 PEP-0484.

中明确指定