Replace `collections.namedtuple` with `dataclasses` or `attrs`
Referencing #100, we need to improve our Elements base class to better handle optional fields while still validating required fields.
There are two major options we can choose for this:
-
dataclasses(built into Python >3.7, available viapip install dataclassesprior to that) https://www.python.org/dev/peps/pep-0557/ -
attrs(user-supported library) https://github.com/python-attrs/attrs
We want to preserve the immutable behavior of network elements for ease-of-reasoning and optimisation purposes. We want to improve the user interface when creating new fields and improve the robustness of our code in validating user input on required fields.
I have a couple of questions related to the "immutable behavior of network elements":
-
Why is not the Edfa element class using an immutable namedtuple for
paramslike all the other element classes? This looks a bit inconsistent. -
What exactly is the importance of this immutable behavior? Currently, for other elements than Edfa, the immutable
paramsis anyway not used after initialization, where it is just used for assigning values to other (mutable) variables. For example inclass Roadmyou haveself.loss = self.params.loss. Then thisroadm.lossvariable is updated bybuild_networkinnetwork.py. Same for Fiber class variablescon_inandcon_outfor example.
I have check the data class: I like it a lot. Only drawback it needs python 3.7, which is a bit of a pain to update.