I'll create a minimal example to replicate this problem and then show you how to fix it, but first let's check that there are no errors with graph union (everything will be done in ipython for my convenience):
In [36]: import igraph as ig
...: ig.union((ig.Graph(), ig.Graph()))
Out[36]: <igraph.Graph at 0x24343faab80>
Ok, we know the union works, let's try a minimal inheritance:
In [37]: class Graph(ig.Graph):
...: ...
...: ig.union((Graph(), Graph()))
Out[37]: <__main__.Graph at 0x24343faac70>
So far, so good. Let's try to add our new __init__:
In [38]: class Graph(ig.Graph):
...: def __init__(self, p, q):
...: self.p = p
...: self.q = q
...: super().__init__()
...: ig.union((Graph(1, 2), Graph(1, 2)))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-38-68cf6a0e1e15> in <module>
4 self.q = q
5 super().__init__()
----> 6 ig.union((Graph(1, 2), Graph(1, 2)))
c:\python38\lib\site-packages\igraph\operators.py in union(graphs, byname)
178 # If any graph has any edge attributes, we need edgemaps
179 edgemaps = any(len(g.edge_attributes()) for g in graphs)
--> 180 res = _union(newgraphs, edgemaps)
181 if edgemaps:
182 graph_union = res["graph"]
TypeError: __init__() got an unexpected keyword argument '__ptr'
There's our error. igraph is expecting Graph to accept the same arguments and keyword-arguments as ig.Graph. This is how we can fix it:
In [39]: class Graph(ig.Graph):
...: def __init__(self, *args, p=None, q=None, **kwargs):
...: self.p = p
...: self.q = q
...: super().__init__(*args, **kwargs)
...: ig.union((Graph(p=1, q=2), Graph(p=1, q=2)))
Out[39]: <__main__.Graph at 0x24343faa400>
We've changed the signature of our __init__ to accept arbitrary positional arguments, our specific parameters as keyword-arguments, then arbitrary keyword-arguments. Now, igraph can pass the same arguments it passed to ig.Graphs. Hope this helps!