Networkx AttributeError: 'DiGraph' object has no attribute '_succ' on inheritence

Networkx AttributeError: 'DiGraph' object has no attribute '_succ' on inheritence

为什么下面的代码

import networkx as nx

class DiGraph(nx.DiGraph):
    def __init__(self):
        self.add_node("a")
        super().add_node('a')

d  = DiGraph()

产生属性错误

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_9038/3565896072.py in <module>
      6         super().add_node('a')
      7 
----> 8 d  = DiGraph()

/tmp/ipykernel_9038/3565896072.py in __init__(self)
      3 class DiGraph(nx.DiGraph):
      4     def __init__(self):
----> 5         self.add_node("a")
      6         super().add_node('a')
      7 

/usr/lib/python3/dist-packages/networkx/classes/digraph.py in add_node(self, node_for_adding, **attr)
    418         doesn't change on mutables.
    419         """
--> 420         if node_for_adding not in self._succ:
    421             self._succ[node_for_adding] = self.adjlist_inner_dict_factory()
    422             self._pred[node_for_adding] = self.adjlist_inner_dict_factory()

AttributeError: 'DiGraph' object has no attribute '_succ'

我的networkx版本是2.4

import networkx as nx

class CusDiGraph(nx.DiGraph):
    def __init__(self):
        super(CusDiGraph, self).__init__()
        self.add_node("a")
        super().add_node('a')

d = CusDiGraph()


# plt
import matplotlib.pyplot as plt
pos=nx.spring_layout(d) # pos = nx.nx_agraph.graphviz_layout(G)
nx.draw_networkx(d,pos)
labels = nx.get_edge_attributes(d,'weight')
nx.draw_networkx_edge_labels(d,pos,edge_labels=labels)

只是改变继承关系。