New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Facades as dataclasses #44
Conversation
Hi @jnnr, like your approach to use pythons dataclass very much! |
Thanks for your feedback, @henhuy!
Good point - in this way, all attributes would have to be defined explicitly in the facade, which is good. Update: This has more implications:
|
Also saw, that *args and **kwargs in |
Thanks for continuing this, @monika-o! |
TODOs: Test
|
… into features/dataclasses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked for all facade classes that have been adapted if their behavior has changed and found only few lines to correct.
In addition, the _facade_requires seem not to be used any more and could be dropped in the class Facade.
@henhuy, @MaGering. @srhbrnds : This feature is almost finished and should help working with tabular in the future. Please have a look or a review or just be informed. The main improvement is that by making the facades into dataclasses we can transparently show their attributes, datatypes and defaults. @henhuy: I adapted the decorator |
This is a draft to show how facades can be implemented as dataclasses. The advantages are:
Special attention has been given to make sure that the behaviour of the classes regarding required and default arguments does not change. This has been checked manually, via the constraint tests and by re-running and comparing an energysystem in the model oemof-B3.
Note: ElectricalLine is imported from oemof.solph but does not inherit from the base class Facade. It has not been changed into a dataclass. It should move to the experimental package once that has been set up.
Problems encountered:
__init__
passes args and kwargs to the parent class (withsuper().__init__(*args, **kwargs)
, which makes it possible to set attributes of the base class that are not explicit in the facade (likeinvest_relation_output_capacity
for storage). To keep this behaviour, I implemented a wrapper that adds that call to the__init__
.__hash__
method that is defined in oemof.network.Node (the hash of the class is defined as the hash of the label). Applying the correct settings (unsafe_hash=False, frozen=False, eq=False, see 6fb68f5), the__hash__
method remains untouched.