我正在修补一些图算法,我想让自己成为一个通用的图/边框架。 我首先创建了一个Edge类:
class Edge:
source = None
destination = None
isDirected = False
isWeighted = False
weight = None
def __init__(self, source, destination, isDirected = False, weight = None):
self.source = source
self.destination = destination
self.isDirected = isDirected
if not weight is None:
self.isWeighted = True
self.weight = weight
def isSameEdge(self, edge: {'help': 'Some helpfull text goes here', 'type': Edge}):
if \
self.isDirected != edge.isDirected or \
self.isWeighted != self.isWeighted or \
self.weight != edge.weight:
return False
if self.isDirected:
if \
self.destination != edge.destination or \
self.source != edge.source:
return False
return True
我收到以下错误消息:
def isSameEdge(self, edge: {'help': 'Some helpfull text goes here', 'type': Edge}):
NameError: name 'Edge' is not defined
我的问题是:
1)如何通知python isSameEdge函数中的edge参数是edge类型
2)我不想限制类型,我只想让Pycharm/任何其他IDE给我提供关于可用于的方法/类变量的提示
引用python.org:
有关详细信息,请查看此PEP
Python 3代码:
与[python 2.7]等价,如下所示:
编辑:定义变量参数数据类型
您应该将其定义为
Union[int, float, None]
相关问题 更多 >
编程相关推荐