为什么 Visual Studio 代码将 "return super().__init__(self)" 插入派生的 class?
Why does Visual Studio Code insert "return super().__init__(self)" into the derived class?
我明白 __init__()
is required to return None
,但是当 Visual Studio 为我自动完成派生的 class __init__()
时,它是这样的:
class Base:
def __init__(self):
print('Base')
class Derived(Base):
def __init__(self):
return super().__init__() # This part is added by VS Code
这显然不是语法问题,因为基础 __init__
是 returning None
,派生的 class 又 return 是嗯
但为什么还要麻烦呢? return 语句在这里有什么作用?
根据 , VS Code seems to do this for all inherited methods, and does not discriminate between __init__()
and other methods. An issue has already been filed in the Python Language Server repo. The issue has been fixed.
我明白 __init__()
is required to return None
,但是当 Visual Studio 为我自动完成派生的 class __init__()
时,它是这样的:
class Base:
def __init__(self):
print('Base')
class Derived(Base):
def __init__(self):
return super().__init__() # This part is added by VS Code
这显然不是语法问题,因为基础 __init__
是 returning None
,派生的 class 又 return 是嗯
但为什么还要麻烦呢? return 语句在这里有什么作用?
根据 __init__()
and other methods. An issue has already been filed in the Python Language Server repo. The issue has been fixed.