如何在python中声明对象类型
我想让IDE(pycharm)知道变量的类型如何在python中声明对象类型,python,class,Python,Class,我想让IDE(pycharm)知道变量的类型 class phone: def __init__(self,): self.device = None def connect(self,): self.device = samsung_object() 现在IDE不知道用于设备的函数/变量。 我希望在init time中它将是三星对象类型。为您将注释转换为代码:) 这将起作用,PyCharm也知道类型 class Samsung: de
class phone:
def __init__(self,):
self.device = None
def connect(self,):
self.device = samsung_object()
现在IDE不知道用于设备的函数/变量。
我希望在init time中它将是三星对象类型。为您将注释转换为代码:) 这将起作用,PyCharm也知道类型
class Samsung:
def foo(self): pass
class Phone:
def __init__(self,):
self.device = Samsung()
def connect(self,):
self.device.foo() # pycharm suggest foo
将注释转换为代码:) 这将起作用,PyCharm也知道类型
class Samsung:
def foo(self): pass
class Phone:
def __init__(self,):
self.device = Samsung()
def connect(self,):
self.device.foo() # pycharm suggest foo
因此,调用
self.connect()
?您可以在\uuuu init\uuuuu
函数的末尾添加self.connect()
,或者调用new\u phone=phone()
在函数的末尾,或者在实例化新电话时调用新电话=电话().connect()