So I have in my project two classes: Circuit and SubCircuit. At some point I may need to construct a SubCircuit from a Circuit. Is there a more elegant way to do that than what's done below in the last 4 lines? Circuit may get some new attributes at some point for example, which would mean that conversion would also need to be updated - basically inviting bugs.
class Gate(abc.ABC):
def __init__(self, size):
self.in_ports = (InPort(self),) * size
self.out_ports = (OutPort(self),) * size
class Circuit:
def __init__(self, size):
self.input = (OutPort(self),) * size
self.output = (InPort(self),) * size
self.gates = []
# ... some other stuff that messes around with these attributes
class SubCircuit(Gate, Circuit):
def __init__(self, circuit=None):
Gate.__init__(self, size)
Circuit.__init__(self, size)
if circuit is not None:
self.gates = circuit.gates
self.input = circuit.input
self.output = circuit.output