[英]Why does Visual Studio Code insert "return super().__init__(self)" into the derived class?
I understand that __init__()
is required to return None
, but when Visual Studio autocompletes a derived class __init__()
for me, it does so like this:我知道
__init__()
需要返回None
,但是当 Visual Studio 为我自动完成派生类__init__()
,它__init__()
:
class Base:
def __init__(self):
print('Base')
class Derived(Base):
def __init__(self):
return super().__init__() # This part is added by VS Code
It's obviously not a syntax issue, as the Base __init__
is returning None
, which the derived class in turn returns as well.这显然不是语法问题,因为 Base
__init__
返回None
,派生类反过来也返回None
。
But why even bother having that?但为什么还要麻烦呢? What purpose does the return statement serve here?
return 语句在这里有什么作用?
As per @Simeon Visser's comment , VS Code seems to do this for all inherited methods, and does not discriminate between __init__()
and other methods.根据@Simeon Visser 的评论,VS Code 似乎对所有继承的方法都这样做,并且不区分
__init__()
和其他方法。 An issue hasalready been filed in the Python Language Server repo. The issue has been fixed .Python 语言服务器存储库中已经提交了一个问题。
该问题已修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.